2.3.2 Associate Script with Elements

Since a script can access any element in a report, in many cases it is possible to write a single large script to perform all tasks. This poses a few problems, however:

A large script tends to grow and become more complicated over time. This makes debugging the script much more difficult.

If a single script affects many elements, whenever you rename or delete one of those elements, the script will generate an “object not defined” error. This kind of dependency makes report maintenance difficult, because it is not clear to developers which report elements might be under the influence of a remote script.

When a script on one element affects the properties of other element, the efficacy of the script depends on the order in which the elements are evaluated. Because the rules for element evaluation (see Script Evaluation) are varied, it can be difficult to predict the final result of the script.

To avoid all of these problems, the script that you place on an element should affect only the properties of that element. For example, if you need a script that modifies the properties of element Text1, then add this script to element Text1. The majority of scripts are element-specific and should therefore each be attached to their associated element.

However, certain scripts need to access multiple elements in order to perform calculations, and it would be difficult to break these up into smaller pieces. In general, if a script works on multiple elements, it should be placed in the onLoad Handler. This eliminates the ambiguity of evaluation order: Since the onLoad handler is called before any element-script is evaluated, all onLoad actions take effect in the current thread.

See Also

Editing Script for information on adding element-level script.

Script Evaluation, for information about the order of element-script evaluation.

onLoad Handler, for information on placing script for pre-query execution.

<< 2.3.1 Keep the Script Small © 1996-2013 InetSoft Technology Corporation (v11.5) 2.3.3 Use log() to View Diagnostic Messages >>