|
Testing scriptsThe 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 Testing for errorsOne way to see if a script is functional 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.
PreflightIn addition to the icons and messages in the Scripts pane, something else can show if your scripts function as expected before generating output:
Preflight executes the template without actually producing output. Be aware that scripts run in a specific order (see The script flow: when scripts run). When one script unintentionally influences the results of another script, changing the order of the scripts in the Scripts pane may help (see Changing the order of execution).
Testing for speed issuesTo measure the time that the execution of scripts will take:
Profiling means running the scripts in the template, with the current record, 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:
You can also see the breakdown of the execution time across different execution stages:
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 settingsNumber of runsBy default, the Script Profiler runs on 1000 instances of all the scripts. To test on a higher or lower number of instances:
SortingIn 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. Script timeoutWhen testing scripts, either by toggling to Preview mode or by using the Script Profiler, a script timeout is active in the Designer, so that scripts that need a very long time to run are stopped after a set time. You can adapt this timeout to your needs, as follows:
The script timeout is not active when generating output.
|
|