ServiceNow client scripts are JavaScript code that runs in the user's browser for client-side
conditioning, validation, and UI logic based on user interaction with forms or list views.
Client scripts are typically used to enhance user experience by dynamically changing form
behavior, validating input before submission, and responding to field changes.servicenow+3
There are four main types of ServiceNow client scripts:
• onLoad: Runs when a form loads.
• onChange: Runs when a field value changes.
• onSubmit: Runs when a form is submitted.
• onCellEdit: Runs when a cell value is edited in a list.c-sharpcorner+3
How to create a client script:
1. Navigate to System Definition > Client Scripts.
2. Click New to open the client script form.
3. Fill in the required fields:
o Name: Descriptive script name.
o Table: The table where the script runs.
o UI Type: Desktop, Mobile/Service Portal, or All.
o Type: Choose onLoad, onChange, onSubmit, or onCellEdit.
o Script: Enter JavaScript code that uses g_form, g_user, and related client
APIs.servicenowwithrunjay+2
Common client script tasks:
• Show/Hide fields and sections.
• Make fields read-only or editable.
• Set or get values in fields.
• Display messages/alerts.
• Form validation.
• Call server-side logic with GlideAjax.
Example: onChange client script
javascript
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
g_form.showFieldMsg('field_name', 'Please review this field', 'info');
This script displays an informational message when a specified field changes.c-sharpcorner
Best practices:
• Use client scripts only when necessary—prefer UI Policies for simple field logic.
• Select the correct UI Type for your scenario (Service Portal use requires either 'All' or
'Mobile/Service Portal').
• Keep scripts performant and maintainable; avoid excessive or complex logic in the
client browser.snowycode+2
Official documentation for further details:
• ServiceNow official client script docs:
https://www.servicenow.com/docs/bundle/yokohama-application-
development/page/script/client-scripts/concept/client-scripts.html.servicenow
• In-depth article and examples: https://servicenowwithrunjay.com/client-script-in-
servicenow/.servicenowwithrunjay
• Best practices and form field references: https://blog.snowycode.com/post/what-is-
a-client-script-in-servicenow.snowycode
1. https://www.servicenow.com/docs/bundle/yokohama-application-
development/page/script/client-scripts/concept/client-scripts.html
2. https://serviceportal.io/docs/documentation/client_scripting.md
3. https://www.c-sharpcorner.com/article/client-scripts-in-servicenow-simplified-with-
real-time-use-cases/
4. https://www.youtube.com/watch?v=SCkKbdZw2aY
5. https://servicenowwithrunjay.com/client-script-in-servicenow/
6. https://blog.snowycode.com/post/what-is-a-client-script-in-servicenow
7. https://noderegister.service-
now.com/kb?id=kb_article_view&sysparm_article=KB0523903
8. https://www.scribd.com/presentation/667144248/3-Client-Script
9. https://qualityclouds.com/documentation/qcr/rules/service-portal-and-client-
scripts/
10. https://www.zoho.com/crm/developer/docs/client-script/client-script-best-
practices.html