Client Scripts
Client Scripts
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.
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.
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