JavaScript is an interpreted, not a compiled, language that evaluates and runs code line in sequence. If JavaScript finds a problem with a code line, it stops. Although the syntax checker of Interactive Reporting Studio Script Editor identifies some obvious syntax errors, many errors are not noticed until runtime.
Identifying whether each line of code executes or fails, as you develop scripts, is a time-effective way to identify and avoid problems.
The Console window displays error messages and alert values that are generated by the JavaScript interpreter. During script debugging cycles, you can write messages to the Console window to track the state of variables and the progress of the script. If a syntax error is detected, the error and the line number in which it occurs are displayed. You can use the line number to move directly to the error in the Script Editor.
You use one of three methods to write to the Console window: Console.Write(), Console.Writeln(), or Alert().Console.Write() and Console.Writeln()are essentially identical. Console.Write() does not add carriage returns at the ends of lines, and Console.Writeln() does add carriage returns.
Console.Writeln() is usually, but not always, the preferred technique. It enables the script to run without user interaction, and the Console window records each line as it is written to the Console.
Note: | Console.Writeln()is spelled with a lowercase l and n. |
The Console window also displays the buffer that contains messages about the errors that occur from when Interactive Reporting Studio starts. Thus, the Console window may display information that is no longer of value.
You can access the Console window from any section within a document; it remains open until you close it. When the Console window is closed, the buffer size is 1,000 bytes. When the Console window is open, the buffer size is 641 bytes.
To work through a challenging section of code, you should use Alert().
Whatever method you use, you must identify the beginning and end of each script and each code line before the script or each code line executes.
Example—A script that moves to the query section and removes limits:
Console.Writeln("Start Query Script") Console.Writeln("Step1") ActiveDocument.Sections["Query"].Activate() Console.Writeln("Step2") ActiveDocument.Sections["Query"].Limits.RemoveAll() Console.Writeln("Step3") Console.Writeln("End Query Script")
For the example script, the Console window displays the following message: