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.

3 REPLIES 3

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