How many types of client scripts in service now ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Service now family,
Can anyone tell me how many types of client scripts in service now ?
Thanks;
Pruthwiraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @PruthwirajS ,
We have 4 types of client script in Servicenow
- onLoad(): When the form loads, before user input.
- onSubmit(): When the form is submitted; can validate or cancel submission.
- onChange(): When a specific field’s value changes on a form.
- onCellEdit(): When a cell value is edited in a list.
https://www.servicenow.com/docs/r/api-reference/scripts/client-scripts.html
Please mark my answer correct and helpful if this works for you
Thanks and Regards,
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @PruthwirajS
There are 4 types of Client Scripts in ServiceNow:
-
onLoad()
Runs when the form is loading, right before the user gets control. Usually used to set initial field visibility, make fields mandatory/read-only, or populate defaults based on existing record data.
-
onChange()
Fires whenever a specific field value changes on the form. It includes parameters like
oldValue,newValue, andisLoadingso you can control logic depending on how the field changed. -
onSubmit()
Runs when the user clicks Save, Submit, or Update. Best used for final client-side validations (you can stop the save action by returning
false). -
onCellEdit()
Runs when a user modifies a field directly from a List view (inline editing), rather than inside the form itself.
For More Information , Please refer this : https://www.servicenow.com/docs/r/xanadu/application-development/scripts/client-scripts.html
Happy to help! If this resolved your issue, kindly mark it as the correct answer ✅ and Helpful and close the thread 🔒 so others can benefit too.
Warm Regards,
Deepak Sharma
Community Rising Star 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @PruthwirajS ,
There are four types of Client Script: onChange, onLoad, onSubmit, or onCellEdit.
- onLoad(): runs when a form loads and before control is given to the user. Typically used to manipulate a form's appearance or content on the screen
- onSubmit(): runs when a form is saved, updated, or submitted. Typically used for field validation
- onChange(): 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
- onCellEdit(): run when a particular field value on a list changes. Typically used to ensure data in a list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @PruthwirajS
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.
- 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.
- 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.
- 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.
- 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.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
