globalInstance()

Mark Birbeck's picture

The standard XForms function instance() must only return instances from the model of the current evaluation context, and although trying to obtain an instance from another model won't result in an error, the return value will be null.

The rationale is to improve performance of XForms processors, since if an author is unable to create dependencies between models, then calculations for each model can be performed on each model individually as necessary, rather than for every model in a form.

Although authors are prevented from creating depencies between models, there will still be occassions when data needs to be moved from one model to another. For this reason formsPlayer adds the globalInstance() function, which can return a reference to any instance in the form. Note however, that if this function is used in bind statement no dependency is created; in other words, if the data in an instance in another model changes, the bind statement will not automatically be recalculated. If a recalculation is needed, then it is the author's responsibility.

A proposal has been made to add this feature to XForms.