Testing client-side scripts
Testing scripts in ServiceNow can be done in a few ways. Fortunately, client-side scripts can be some of the easiest to test, because the script is running in front of the user, and therefore, logging and feedback on scripts can be shown directly to the user, too.
Alert
One of the simplest ways to debug client script is to use the alert functionality. alert
simply pops up a message window displaying information you choose to include. This can be useful for showing the values of fields or variables at certain times, or simply to confirm that certain functions were entered.
Let's see how alert
works in the following code:
alert('Debug Message');
The preceding script will simply show a pop-up message to the user saying Debug Message
. It is a simple line of code to write and provides instant feedback.
Let's have a look at how we can use alert
to help us test our code:
function onLoad() { alert('Start of script'); var shortDescBefore = g_form.getValue('short_description'...