Please use for the latest documentation.

This site is for reference purposes only and may not be accurate for the latest ServiceNow version

JavaScript Debugger

From Wiki Archive
Jump to: navigation, search
Note: This article applies to Fuji and earlier releases. For more current information, see Script Debugger at

The ServiceNow Wiki is no longer being updated. Visit for the latest product documentation.

{{Topic|Scripting Glide and Jelly


The JavaScript Debugger is a tool that allows application developers and administrators to efficiently debug scripts that drive the applications they develop and support.

Administrators can set breakpoints in business rules and script includes to pause execution on the specified lines. Execution can be controlled line-by-line and variables within the JavaScript environment can be inspected.

This feature is available starting with the Dublin Release.

Note: The JavaScript Debugger requires Internet Explorer 9 or higher, Firefox, Chrome, or Safari.

Starting the JavaScript Debugger

  1. Open the JavaScript console by clicking the debug icon (Debug.gifx.gif).
    • UI14: click the gear icon (GearIconUI14.png) on the banner frame and then click the debug icon.
    • UI11 and Classic: click the debug icon on the banner frame.
    A new pane opens at the bottom of the screen. It shows the JavaScript Debugger tab and may also show JavaScript Log and Field Watcher tabs.
    Launching the JavaScript Debugger

  2. Select the JavaScript Debugger tab.
    The JavaScript Debugger is automatically turned on when the debug icon is clicked, and turned off when you click the close button (X button.png) to close the JavaScript console.
  3. If needed, you can click the on/off button (On-off.png) when the JavaScript console is open to turn the JavaScript Debugger off. This can be useful if you want to keep displaying the JavaScript logged for a particular activity without continuing to log new activity.

Using the JavaScript Debugger

  1. 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.
    Selecting a Script

  2. Set breakpoints by clicking in the gutter next to the desired line.
    The gray circles indicate where the breakpoints were set and that the JavaScript Debugger has been turned off.
    Setting a Breakpoint

  3. Perform an action to execute the specified script. For example, submit a form.
    The blue circles indicate that the JavaScript Debugger is turned on. Execution pauses on any evaluated line that has a breakpoint, and changes that line's circle to red.
    Red Breakpoint.png

  4. Step through the surrounding code using the debugger controls.
  5. Breakpoints can be removed from a script simply by clicking on the breakpoint.
Note: Breakpoint configurations are saved when they are specified. The administrator does not need to reset breakpoints every time the JavaScript Debugger is turned off or a session expires.

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.

Note: Breakpoints set in the JavaScript debugger do not stop in AJAX-related scripts like GlideAjax and Reference Qualifiers.

Controlling Code Execution

Administrators can control code execution after a breakpoint has been hit with the following control buttons on the Breakpoints tab.

Button Description
px20 The On/Off button is used to turn debugging on and off. The button turns red when debugging is enabled and returns to black when debugging is disabled.
px20 The Next Breakpoint button is used to advance to the next breakpoint.
px20 The Step Over button is used to advance to the next evaluated line of the current script. Note that the next evaluated line won't always be the line immediately following the current line. A block of control logic, for example, may be skipped entirely if its condition does not evaluate to true.
px20 The Step Into button is used when execution stops on a method call. The debugger stops on the first line of the executed method.
px20 The Step Out Of button is used to exit from the currently executing method.

Setting Breakpoint Options

Breakpoint options allow you to control how the debugger handles exceptions. To view the Breakpoint Options, click the menu icon (App Nav icon.png) beside the Scripts tab. To close the Breakpoint Options, click the icon again.

Handling Exceptions

The JavaScript debugger provides exception handling capabilities beyond what exists in a normal script environment. Administrators can specify whether the debugger pauses when exceptions occur. Pausing on exceptions allows the execution context to be explored and may indicate the root cause for the exception.

Exception handling can be configured through the configuration menu beside the Scripts tab.

Breakpoint Options.png

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.

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.

Call Stack.png

Exploring Variables

Administrators can explore all JavaScript variables in the execution context using the variable explorer. The debugger provides tree views of the global and local scope, as well as any closures wrapping the local scope. Administrators can also configure watch variables to easily monitor variables across multiple scopes.

Watch Variables

To set a watch variable:

  1. Click the Variables tab.
  2. Click the plus (+) icon on the right of the Watch Variable header.
    Watch Variable.png

  3. Enter the variable name.
  4. Click Add.

To remove a watch variable:

  1. Point to the variable name.
    A remove button appears.
  2. 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.

Debugging Considerations

Debugging can cause running transactions to wait for significant periods of time. For this reason, the JavaScript Debugger initializes a new semaphore set so that debugging does not affect the number of default semaphores that are available. The additional semaphore set is visible on /

Debugging also requires that some transactions are interrupted for prolonged periods, but safeguards have been put in place to ensure that transactions cannot be paused indefinitely. Paused script executions resume when the system detects that the JavaScript Debugger has lost connectivity.