Writing scripts to populate JavaScript Table

Once you created a JavaScript Table and specified its structure, you need to write a script that will populate the table with the required data.

About this task

You write the script in the JavaScript Table editor according to general JavaScript syntax rules. The editor opens automatically after you close the Create New JavaScript Table wizard.

To manage the content of a JavaScript Table, you can also use the following special functions of the table global object:
appendData()
Inserts the data specified by a two-dimensional array to the end of the JavaScript Table.
replaceData()
Completely replaces the content of a JavaScript Table with the data specified by a two-dimensional array of the following form: [[<row 1 column1>, <row 1 column 2>,...], [<row 2 column 1>, <row 2 column 2>,...],...].
eraseData()
Removes JavaScript Table records that satisfy the specified SQL condition. If you call eraseData() function without arguments or with null argument, all table records are removed.
setTag()
Links the JavaScript Table with some additional information specified by a string. This information can be retrieved by the getTag() method. To clear the information, use setTag() with null argument or without arguments.
getTag()
Returns the additional information related to the JavaScript Table.
include()
You can include external code in your JavaScript Table script by using the include() method.

To trace HTTP request, response, and record logs, use the log() function.

You can also use prompted variables in the script. A user will be prompted to enter variable values when running a query based on the created JavaScript Table. If you use a prompted variable in the script, note the following peculiarities:
  • The JavaScript Table cache is ignored.
  • When a user works with a JavaScript Table in QMF for WebSphere┬«, all the retrieved data will be available to that user only.

You can work with the preset modules or create custom ones.

When you finish working with the script, save the changes and close the editor.

Procedure

  1. If you want to work with the preset modules, add JavaScript to them. For more information about modules, see the Modules in JavaScript data sources topic of Administrator Help.
  2. To add a user module:
    1. In the Repository Explorer view, right-click the Modules node of the data source and select New > JavaScript Module.
    2. In the New JavaScript Module wizard, specify the name for the JavaScript Module in the Name field and click Finish to open the JavaScript Module editor.
  3. Type script in the modules and save them.
    Important: If you work with preset modules, do not duplicate names of variables in different modules to avoid conflicts during their execution.