0% found this document useful (0 votes)
17 views5 pages

Client Scripts

The document discusses client scripts in ServiceNow and how they can be used to modify form fields and values when events occur on the client side like loading, submitting, or changing a field value. It provides examples of how client scripts can be used and explains the different types of client script events - onLoad, onChange, onSubmit, and onCellEdit.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views5 pages

Client Scripts

The document discusses client scripts in ServiceNow and how they can be used to modify form fields and values when events occur on the client side like loading, submitting, or changing a field value. It provides examples of how client scripts can be used and explains the different types of client script events - onLoad, onChange, onSubmit, and onCellEdit.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Client scripts allow the system to run JavaScript on the client (web browser) when client-

based events occur, such as when a form loads, after form submission, or when a field
changes value.
Use client scripts to configure forms, form fields, and field values while the user is using the
form.

Client scripts can:


• make fields hidden or visible
• make fields read only or Editable
• make fields optional or mandatory based on the user's role
• set the value in one field based on the value of other fields
• modify the options in a choice list based on a user's role
• display messages based on a value in a field

Client Script will execute in four ways:

onLoad() — runs when the system first renders the form and before users can enter data.
Typically, onLoad() client scripts perform client-side-manipulation of the current form or set default
record values. (Runs when a form is loaded)

onSubmit() — runs when a form is submitted. Typically, onSubmit() scripts validate things on the
form and ensure that the submission makes sense. An onSubmit() client script can cancel form
submission by returning a value of false. (Runs when a form is submitted)

onChange() — runs when a particular field value changes on the form. The onChange() client
script must specify these parameters. (Runs when a particular field value changes)
• control: the DHTML widget whose value changed.
Note: control is not accessible in mobile and service portal.
• oldValue: the value the widget had when the record was loaded.
• newValue: the value the widget has after the change.
• isLoading: identifies whether the change occurs as part of a form load.
• isTemplate: identifies whether the change occurs as part of a template load.

onCellEdit() — runs when the list editor changes a cell value. The onCellEdit() client script
must specify these parameters. (Runs when a cell on a list changes)
• sysIDs: an array of the sys_ids for all items being edited.
• table: the table of the items being edited.
• oldValues: the old values of the cells being edited.
• newValue: the new value for the cells being edited.
• callback: a callback that continues the execution of any other related cell edit scripts.
If true is passed as a parameter, the other scripts are executed or the change is committed if
there are no more scripts. If false is passed as a parameter, any further scripts are not
executed and the change is not committed.

How to create client script:


1) In the left navigation under System Definition, we will find the client script
2) Click on new button to create Client script:

-→ Actions gets triggered based on these 4 types of events:


OnLoad():

If we select the onload then when the page loads, the client script will run.

OnChange():
onChange() client script will get executed when user change any value in an existing form.
OnSubmit():
onSubmit() client script will get executed when user submits the form.

onCellEdit():
onCellEdit() is used in list view. Cell means a particular row inside a column (Like a excel cell). For list view in
ServiceNow we will get the value as a tabular form so here one value is like cell value. So here if we want to
modify any value and trigger a client script then we can use onCellEdit

You might also like