XFA support > XFA scripting > Considerations when scripting

Considerations when scripting
Scripting in the layout DOM
The layout DOM is first created completely, and distributed over pages, content areas, etc. After this, all layout-ready and preprint scripts are run in the order specified in the XFA 3.3 specification. If any layout-ready or preprint script changes the layout DOM in a way that may cause objects to switch page, the layout DOM will be completely rebuilt.
Rebuilding the layout DOM will delete:
All other layout objects (such as fields from the form DOM) are preserved, and so are the values of these layout objects.
To preserve the correct values, no layout scripts for form objects are run after the layout DOM is rebuilt. Only scripts attached to the dynamically created layout objects (overflow leaders, master page objects etc.) are run this time.
The layout DOM scripts will only run once for each object with some exceptions:
This means you must be careful when using global variables and when initializing them, or when accessing fields and other values in dynamically created subforms in objects in the form DOM:
Example: subform.field.x = subform.field.x + 100; in an overflow leader will cause the subform.field.x to be increased by 100 the first time the layout DOM is created. If the layout DOM is recreated once more, 100 more will be added to x.
Global variables declared inline in java scripts
Global variables declared inline in java scripts in the form DOM, e.g. initialize or form ready, cannot be used in the layout DOM with the initialized values. There is one exception to this – global variables declared in dedicated script objects. These variables can be initialized in form DOM scripts and be used in layout DOM scripts.
Script execution order
The script execution order for objects within an Event type in XFA is undefined. Do not write scripts that are depending on any particular script execution order.
OpenText StreamServe 5.6 Updated: 2013-03-01