

This is causing the script to return early, and not do what I expected it to do. I can use the buttons at the top-right of the debugger to step line-by-line through my code, or even into or out of a given function-call, or I can use step over to remain at the current level of the call stack (meaning, keep the debugger on my code).īy advancing step-by-step through my code, I can see that it’s evaluating my if block to be true, because assigneeMgrID is blank.
#SERVICENOW SCRATCHPAD CODE#
Since the code paused after that variable was assigned, we would expect that variable to have a value! that’ll show you the values of the variables in your code at the moment the code halted.Īs you can see in the image to the right, the variables in the local function scope in my code look as you’d expect, except for assigneeMgrID. In the Scope section, Local is usually going to be the most relevant bit. Collapse Call Stack, and you’ll see Scope. By default (in Chrome), this will be just below the Call Stack section on the right side of the debugger. This can all look pretty overwhelming at first, but the main thing to pay attention to, is the Scope section. Join me after the jump, for a walk-through!
#SERVICENOW SCRATCHPAD HOW TO#
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. In fact, you can! Better yet, you can put calls to the debugger directly in your code! 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?” 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! 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. When available, that tool is incredibly useful but unfortunately, it does not work with client scripts. So when you configure the change client script you have to select “Field name”, basically the field the code should execute if there is any change happen on the field.Įxample code to make short description mandatory when the category is security.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. OnChange client scripts are executed when there is a change on the field on which the client script is written. G_tValue('short_description','This is new incident' )

So for example populate you want to populate short description, email, caller/requester on a load of a new incident. So best use is to set some defaults to make fields mandatory or read-only if some complex conditions are there. ServiceNow onload client script is executed when the form is loaded in the browser. There are 4 types of client scripts onload, onChange, onCellEdit, onSubmit, and scripts are executed when the form is loaded, changed, and submitted. Basically, it runs when an event occurs on the form, form loading, form changing or form field value change, form submission. ServiceNow Client Script runs/executes on the client (web browser – Chrome, Mozilla) and the programming language is JavaScript. Client script is one of the most used client-side scripts. There are two types of scripts in ServiceNow server-side and client-side, in the client-side, there are various areas such as UI action, UI policy, UI page, UI script, UI Macro, client script.
