When dealing with server-side scripts, the ServiceNow Debugger makes debugging relatively easy (most of the time), as you can actually see into the call stack, and the contents of your server-side variables as you step through your code, line-by-line. When available, that tool is incredibly useful; but unfortunately, it does not work with client scripts.
So, how do you troubleshoot client-side scripts in ServiceNow? Well, since those scripts execute inside the user’s browser, you’re going to have to use some browser-magic to make that happen. The good news is, modern browsers already have an incredible debugger that’s at least as good as the server-side script debugger in ServiceNow, built right in!
The question then becomes: “How do I trigger the client-side debugger? I can’t easily put breakpoints in my code that runs client-side, especially if it runs on-load; right?”
In fact, you can! Better yet, you can put calls to the debugger directly in your code!
In this short article, we’re going to see exactly how to do that, using a not-very-smart Client Script that runs on the Incident form. Join me after the jump, for a walk-through!