Testing scripts

The quickest way to test that scripts work as expected, is to click the Preview tab at the bottom of the workspace.

You can even do this while creating a new script, either with a Script Wizard or in the expanded script editor. Click Apply at the bottom of the script editor to see the effect of the script on the Preview tab of the Designer.

Note that scripts that use values of data fields can only be effective when a data file or Data Mapping Configurationis open. See Loading data.

Test for errors

Another way to 'test' a script is to take a look at the Scripts pane.

Hover over the name of a script in the Scripts pane to highlight parts of the template that are affected by the script.

Icons on the name of scripts in the Scripts pane can show a warning, information or error icon.

  • The information icon (i) shows that the selector of the script does not produce a result in the current section.
  • The warning icon (!) appears, for example, when a script refers to an unknown field in the record set, or when ; is missing after a statement.
  • The error icon (x) displays when the script results in an error, for example, when it uses an undeclared variable.

In addition to the icons and messages in the Scripts pane, there is another way to see if your scripts function as expected before generating output:

  • On the Context menu, click Preflight.

Preflight executes the template without actually producing output and it displays any issues once it’s done.

It will tell, for example, which selectors were not encountered in the template.

Test for speed issues

To measure the time that the execution of scripts will take:

  • On the Context menu, click Profile scripts.

Profiling means running the scripts in the template, to see how fast scripts in the Scripts pane execute. It helps greatly in troubleshooting performance issues caused by scripts.

After running the Script Profiler you can see in which sections the script has run:

  • Hover the mouse over a value in the column Count to see the number of times that the script has run, per section.

You can also see the breakdown of the execution time across different execution stages:

  • Hover the mouse over a value in the column Elapsed to see the time elapsed (in milliseconds) since the start of the session. In the Scripts Profiler, the scripts are by default sorted based on the values in the Elapsed column, from high to low.
  • Hover the mouse over a value the column Delta to see the difference between the time elapsed (in milliseconds) in the previous session and in the current session.

The script execution stages are:

Query: the time it takes to find the selector in the template.

Looking for text is a rather lengthy operation. Use an ID (possibly in combination with a text) instead of a text selector to make the query faster. For more tips, see Optimizing scripts.

Execution: the time it takes to execute the script. If you are an experienced JavaScript coder you may be able to optimize the code to speed up the execution of the script.

Functions that actually change the content of the template (for example,append()) are comparatively time consuming. Avoid using such functions in a loop. For more tips, see Optimizing scripts.

Note that the times vary slightly per run of the Script Profiler. Run the Script Profiler a number of times and calculate an average from the results, before trying to speed up the execution of a script.

Script Profiler settings

Number of runs

By default, the Script Profiler runs on 1000 instances of all the scripts. To test on a higher or lower number of instances:

  1. On the menu, select Window > Preferences.
  2. Click Scripting.
  3. Set a number of iterations (maximum one billion) and click OK.
Sorting

In the Scripts Profiler, the scripts are by default sorted based on the values in the Elapsed column, from high to low. Click any of the columns to sort the scripts according to the values in that column.

 
  • Last Topic Update: 24/01/2017 09:32
  • Last Published: 7/6/2017 : 9:49 AM