100% found this document useful (1 vote)
84 views

Client Scripts ServiceNow 1702754037

Client scripts in ServiceNow allow users to manage the behavior of forms, fields, and lists through client-side JavaScript. Some common uses of client scripts include making fields mandatory, setting dependent fields, modifying lists, and validating submissions. Client scripts use JavaScript APIs and can run on load, on change of a field, on form submit, or when editing a list cell.

Uploaded by

Huseyin Demir
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
84 views

Client Scripts ServiceNow 1702754037

Client scripts in ServiceNow allow users to manage the behavior of forms, fields, and lists through client-side JavaScript. Some common uses of client scripts include making fields mandatory, setting dependent fields, modifying lists, and validating submissions. Client scripts use JavaScript APIs and can run on load, on change of a field, on form submit, or when editing a list cell.

Uploaded by

Huseyin Demir
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

ServiceNow

Client Scripts
Client Scripts manage the behavior of forms, fields, and lists in real time & execute client-side
(web browser).
Some basic use cases of Client Scripts are:
1. Make fields mandatory.
2. Set one field in response to another.
3. Modify choice list options.
4. Hide/Show form sections.
5. Display an alert.
6. Hide fields.
7. Prohibit list editing.
*Note: Backend name for the client script table is sys_script_client.
Or you can Navigate through Application Navigator [All>System definition>Client
Scripts].

Enter the name for your client Scope of the Client Script.
script here. Execute the script for
.Select the
table forms from any extending
tables when selected.
Select whether the
script executes for If Global is selected the script
Desktop only, applies to all Views. If the
Mobile / Service Global field is not selected you
Portal only, or All must specify the View.

select when the


script runs:
onChange, This field will be visible only This field will be only visible when the global
onLoad, when type is onChange or checkbox is unchecked.Here you can set a
onCellEdit. shows on which particular view on which the script will apply.
field to which script applies.
Here you can write your
script.

We have some method which are used for DOM Manipulation like
(getElement(),getElementByID()) so to avoid this manipulation servicenow by
default check this box if we use these method with the checked checkbox it will
not perform there respected funtionalities.

JavaScript APIs:
Provide classes and methods that can be used in scripts to define the functionality of the
platform.
Client-Side Classes Server-Side Classes
GlideRecord GlideRecord
GlideForm GlideAggregate
GlideAjax GlideDateTime
GlideUser GlideSystem
GlideList GlideElement
Types of Client Script:
1. onload Client Script 2. onChange Client Script

3. onSubmit Client Script 4. onCellEdit Client Script

1) onload Client Script:


• Script runs when a form loads and before control is given to the user.
• Typically used to manipulate a form's appearance or content on screen.

Select type as onLoad

This function will get automatically populated

and you can add your code with in this function.


2)onChange Client Script:
• Script runs when a particular field value changes.
• Typically used to Respond to field values of interest or modify one field value in response
to another.

Select type as onChange.

This function will get automatically populated

and you can add your code with in this function.

Script must specify these parameters:


• Control: name of the object (field_name) whose value just changed. The object is
identified in the Field name field on the Client Script form.
• OldValue: value of the control field when the form loaded and prior to the change. For
example, if the value of Assigned to changes from Jai to Abhijeet the value of the parameter
oldValue is Jai. oldValue will always be Jai (the value when the form loaded) no matter
how many times the Assigned to value changes after the original form load.
• NewValue: value of the control field after the change. For example, if the value of
Assigned to changes from Jai to Abhijeet, the value of the parameter newValue is Abhijeet.
• IsLoading: boolean value indicating whether the change is occurring as part of a form
load. Value is true if change is due to a form load. A form load means all of a form's fields
changed.
• IsTemplate: boolean value indicating whether the change occurred due to population of
the field by a template. Value is true if change is due to population from a template.
3)onSubmit Client Script:
• Script runs when a form is saved, updated, or submitted.
• Typically used for field validation.

Select type onSubmit.

This function will get automatically populated and you


can add your code with in this function.

4)onCellEdit Client Script:


• Script runs when a particular field value on a list changes.
• Applies to all records selected.

Select type onCellEdit here.

This function will get automatically populated

and you can add your code with in this function.


Script must specify these parameters:
• sysIDs – sys_id of the edited item
• table – the table name of the edited item.
• oldValues – the old value of the edited cell.
• newValue – the new value of the edited cell. Is the same for all edited items.
• callback – a callback will continue the execution of other related cell edit scripts.
You must pass back either true or false in the callback function. 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.

You might also like