In this article we’ll explore ServiceNow – client script . In ServiceNow there are many client side programming areas like Client Script, UI Page, UI macro, UI script, UI Action, UI Page UI, Policy, etc.,

Client Script:

Client scripts allow the system to run JavaScript on the client (web browser) when client-based events occur, such as when a field changes value, after form submission, or when a form loads.

Client scripts are used to configure form fields, field values and form while the user is using the form. Client scripts can:

  • make fields hidden or visible
  • make fields read only or writable
  • make fields mandatory or non mandatory based on the user’s role
  • set the value of field based on the value of other fields
  • modify the options in a list based on a user’s role
  • display hint based on a value in a field


We all have email account , when we click on on sign in button without giving the login details, We will get an error.
If we implement above example in ServiceNow, we create new incident and click on on submit button without filling any required information, then error messages flaunted to us . Error message like requester is blank, description is empty.

ServiceNow Client Script is employed for validation purpose, to form field read only, to create fields hidden, to form fields mandatory, populate value on static value on the sector, to display informational message, for generate popup on button click or on page load etc., remove or add values in dropdowns, auto populating the sector etc. There are plenty of many features which is taken care by client scripts in ServiceNow.

So, script we write in client script will get execute on the client-side means user will experience the interface interaction which suggests when the user will fill the form, or when a page is loaded, or when a form is modified or when the form is submitted.

Types of Client Script:

There are four different types of client script

  • onload()
  • onChange()
  • 0nSubmit()
  • onCellEdit()

onload() Client Script:
The code must be written in onload() client script area then the script get executed, when the form is loaded and before the user have entered any input or data within the form.

For e.g. You click on create new incident and incident form gets loaded ahead of you, which contains some pre-populated values in fields like requester name, requester email id, location, etc.

So make sure you change the Type to onLoad before writing the script.

onChange() Client Script:
The code must be written in onChange() client script area then the script get executed when user change any value in an existing form.

For eg. In Incident form when user select the state as pending then another field appears like Reason for Pending.

So make sure you change the Type to onChange before writing the script.

onSubmit() Client Script:
The code must be written in onSubmit() client script area then the script get executed when use submit button in the form. The code is used to validate the form.

For eg: In incident form if the the user selecting the issue occurred date in future where issue occurred date should not be in future when you click on Summit button. Then client script validate the date field and display the error message.

onCellEdit() Client Script:
The code must be written in onCellEdit() client script area then the script get executed when user change any value within the list view.
Navigate to Incident Management and click on on All link or open link or closed link. After clicking on mentioned link you find list view. When user change any value or want to vary any value directly from list view, then the code must written as onCellEdit client script type.

I hope above information helped you to understand ServiceNow client script

0 CommentsClose Comments

Leave a comment

Newsletter Subscribe

Get the Latest Posts & Articles in Your Email

We Promise Not to Send Spam:)