Client script examples
Quick answer
Client Scripts react to form events in the browser. Keep them light and never trust them for security.
Key takeaways
- onChange: react to a field
- onLoad: default a field
- onSubmit: validate
Client Scripts react to form events in the browser. Keep them light and never trust them for security.
onChange: react to a field
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') return;
g_form.setValue('urgency', newValue);
}onLoad: default a field
function onLoad() {
if (g_form.getValue('category') === '')
g_form.setValue('category', 'inquiry');
}onSubmit: validate
function onSubmit() {
if (g_form.getValue('short_description') === '') {
g_form.addErrorMessage('Description is required');
return false;
}
}Want to learn this properly?
Our live, instructor-led ServiceNow Training covers this hands-on, with real projects and a certification path.
Check your understanding
Where do client scripts run?
- A. In the browser
- B. On the server
- C. On the MID Server
Show answer
A. In the browser
Client scripts execute in the user's browser.
What does returning false from onSubmit do?
- A. Stops the form from saving
- B. Reloads the form
- C. Nothing
Show answer
A. Stops the form from saving
Returning false cancels the submit.
Frequently asked questions
What does the term Client script examples refer to in ServiceNow?
Client Scripts react to form events in the browser. Keep them light and never trust them for security.