How many types of client scripts in servicenow?

tnjrameshbabu
Giga Contributor

Hi Family,

 

Can any one tell me how many types of client scripts in servicenow?

 

Regards,

Rameshbabu Lakshminarayanan

5 REPLIES 5

Vinayak2443
Tera Contributor

Hi @tnjrameshbabu,

There are mainly 4 types of client scripts in ServiceNow .

onLoad: Runs once when the form opens. It is used to initialize the form, such as setting default values, hiding or showing fields, making fields read-only, or displaying messages.
Example: Displaying a welcome message when an Incident form is opened.

onChange: Runs whenever the value of a specified field changes. It is commonly used to validate input, update other fields, or change field properties like mandatory or read-only.
Example: Making the Assignment Group field mandatory when the Priority is set to High.

onSubmit: Runs when the user clicks Save, Update, or Submit, before the record is sent to the server. It performs final validation and can stop the form from being submitted if conditions are not met.
Example: Preventing the record from being saved if the Short Description field is empty.

onCellEdit: Runs when a user edits a field directly in a list view using inline editing. It is used to validate or control changes made from the list without opening the record.
Example: Displaying a warning when the Priority is changed to High directly from the Incident list.

onEdit: Used only in the ServiceNow Mobile app. It runs when a record is edited on a mobile device and is used for mobile-specific client-side behavior.
Example: Automatically displaying a message or updating a field when a record is edited in the ServiceNow Mobile app.

g_form methods commonly used in Client Scripts

Method Purpose
g_form.getValue()Get a field value
g_form.setValue()Set a field value
g_form.setMandatory()Make a field mandatory or optional
g_form.setReadOnly()Make a field read-only or editable
g_form.setVisible()Show or hide a field
g_form.addInfoMessage()Display an informational message
g_form.addErrorMessage()Display an error message
g_form.clearValue()Clear a field value
g_form.showFieldMsg()Show a message below a field

In day-to-day ServiceNow development, you'll most commonly work with onLoad, onChange, and onSubmit.

Please accept the solution and mark it helpful if it helped you.
Regards,
Vinayak