Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Client Script

sparit3737
Tera Contributor

what is Client Script and What its type of Client Script and what exculty use in services now.

5 REPLIES 5

Mehta
Tera Contributor

Hi @sparit3737 , 

 

A Client Script in ServiceNow is a piece of JavaScript code that runs entirely on the client side (the user's web browser) rather than the server. These scripts manage and manipulate the immediate behavior of forms and fields, allowing you to configure interactive layouts, validate real-time user input, and display contextual notifications without forcing a full page refresh.

 

There are 4 types of Clients Script : On Load, On Submit, On change and On Cell Edit.

 

Script Type

Trigger Point

Common Use Case

onLoad

When a form finish loading in the browser.

Pre-populating defaults or formatting the initial view.

onChange

When a user modifies a specific field value.

Showing or hiding elements dynamically based on choice.

onSubmit

When a user clicks Save or Submit.

Validating fields to block data errors before transmission.

onCellEdit

When a field value is modified from a list view rather than a form.

Enforcing data integrity across bulk updates.

yashkamde
Giga Sage

Hello @sparit3737 ,

 

Client Scripts are scripts that run on the client-side, meaning they execute within the user's browser when certain actions occur on a form or a UI page.

 

Types of Client Script :

1) onLoad: Runs automatically when a form or page initially loads and finishes rendering.

  • Use case: Setting a default value, showing a welcome message, or setting focus on a specific field.

2) onChange: Executes when the value of a specific monitored field changes.

  • Use case: Dynamically clearing or populating fields, or auto filling an Assignment Group based on the chosen Category.

3) onSubmit: Triggers right when a user attempts to save, update, or submit a form.

  • Use case: Validating user input and stopping form submission if mandatory details are missing or invalid.

4) onCellEdit: Runs directly on a list view when a user edits a cell value without opening the actual record form.

  • Use case: Quick validation or automated changes when updating list rows inline.

 

If my response helped mark as helpful and accept the solution.

Also Refer this for real time scenarios :

Client script realtime Scenarios

Tanushree Maiti
Tera Patron

Hi @sparit3737 

 

In ServiceNow, there are four main types of Client Scripts. Each type is triggered by a specific user action or browser-side event and is used to enhance the user experience on forms and lists.

  1. onLoad()

Trigger: Executes when a form finishes loading in the browser.

Common Use Cases:

  • Setting default field values.
  • Showing or hiding fields and sections.
  • Making fields read-only or mandatory based on conditions such as user roles.
  • Initializing form behavior when the record is opened.

 

  1. onChange()

Trigger: Executes when the value of a specified field changes.

Common Use Cases:

  • Auto-populating related fields.
  • Displaying validation messages or alerts.
  • Dynamically showing, hiding, enabling, or disabling fields based on user selections.
  • Performing client-side validation.

Note: The isLoading parameter is commonly used to prevent the script from running while the form is still loading.

 

  1. onSubmit()

Trigger: Executes when a user attempts to save, submit, or update a form.

Common Use Cases:

  • Performing final validation checks before data is sent to the server.
  • Ensuring required business conditions are met.
  • Displaying confirmation messages or preventing invalid submissions.

Note: Returning false from an onSubmit Client Script prevents the form from being submitted.

 

  1. onCellEdit()

Trigger: Executes when a user edits a field directly within a list view using inline editing.

Common Use Cases:

  • Validating changes made from a list.
  • Enforcing data integrity rules during inline edits.
  • Controlling or restricting bulk updates.

Note: This script type uses parameters such as sysIDs, table, oldValues, newValue, and a callback function to validate and approve or reject the change.

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti