|Note: The latest release this documentation applies to is Fuji. For the Istanbul release, see Script debugger. Documentation for later releases is also on docs.servicenow.com.|
This feature is available starting with the Dublin Release.
- UI14: click the gear icon () on the banner frame and then click the debug icon.
- UI11 and Classic: click the debug icon on the banner frame.
- Click the Scripts tab and click the script you want to debug. You can search for scripts by name or type, or by table if the script is related to a business rule.
- Set breakpoints by clicking in the gutter next to the desired line.
- Perform an action to execute the specified script. For example, submit a form.
- Step through the surrounding code using the debugger controls.
- Breakpoints can be removed from a script simply by clicking on the breakpoint.
|Note: The Scripts tab includes a script editor. If you make changes to a script, a Save button appears for saving the record. To prevent syntactical errors, all script changes are validated. Scripts cannot be hot swapped, so changes do not take effect until after any existing executions have completed.|
3.1 Controlling Code Execution
Administrators can control code execution after a breakpoint has been hit with the following control buttons on the Breakpoints tab.
3.2 Setting Breakpoint Options
Breakpoint options allow you to control how the debugger handles exceptions. To view the Breakpoint Options, click the menu icon () beside the Scripts tab. To close the Breakpoint Options, click the icon again.
3.2.1 Handling Exceptions
Exception handling can be configured through the configuration menu beside the Scripts tab.
Three exception handling configurations are available:
- Never: Do not break on any exceptions. The script evaluator identifies any exceptions and a stack trace appears in syslog.
- Uncaught: Only break if the exception occurs outside of a try and catch block
- All: Break whenever an exception occurs.
|Note: Debugger exception handling controls only how the debugger reacts to exceptions. It does not affect how the script evaluator reacts to exceptions.|
4 Displaying the Call Stack
It is often useful to know what calls led up to a breakpoint. The Call Stack tab displays call stack information for the first breakpoint that has been executed, indicated by the red circle. As you move to subsequent breakpoints, the call stack information displays.
5 Exploring Variables
5.1 Watch Variables
To set a watch variable:
- Click the Variables tab.
- Click the plus (+) icon on the right of the Watch Variable header.
- Enter the variable name.
- Click Add.
To remove a watch variable:
- Point to the variable name.
- A remove button appears.
- Click remove.
Closures are all of the scopes that wrap a function definition. Variables in these scopes are visible when the function is invoked and can be viewed in the variable explorer.
6 Debugging Considerations