Adding a JavaScript code element
Use a JavaScript code element for each block
of code you are using in a template.
Restriction:
The JavaScript code
element is available only in version 2 templates.
The JavaScript code
element is available only in version 2 templates.About this task
JavaScript can
range from simple arguments to complex scripts.
- For simple arguments, you can apply script to the content of an element, such as a Text element. Double-click the text element, select the Script Expression tab, and enter a script.
- For complex scripts, you can use this task to apply your script by using the JavaScript code element.
The following are benefits to using the JavaScript
code element over the Script Expression tab of an element:
- You can reuse scripts from other users.
- You can group calculations without worrying about the order of their execution.
- You can create normal and complex data structures, such as collections, and continually add to
them.Tip: Starting in Rational® Publishing Engine V2.1 release, you can call the function that is defined in one JavaScript code element in another JavaScript code or Script Expression by setting a Library script property on the script code. To set the Library script property, go to the Properties view of the JavaScript Code element and select the Specific tab, enable the Library script check box. For more information about the library script property, see JavaScript code element properties.
The JavaScript file utils.js is included in your installation files and in the predefined Document Builder component files for you to use for simple JavaScript, like including the current date in report output.
To see a list of the existing JavaScript code in your template, click . The Search view opens and a list of elements that use JavaScript is displayed. Native filters are not considered JavaScript in this context. Native filters are not listed in the search results.
Procedure
Working in the JavaScript editor
Use the JavaScript editor to work on your
script with syntax coloring and content assist.
About this task
Content assist shows in a pop-up window a list of valid alternatives for completing the current line of code. To activate content assist, press Ctrl + Space.

