KEMBAR78
Examples | PDF
0% found this document useful (0 votes)
8 views2 pages

Examples

This document provides a beginner's exercise for creating and using ServiceNow client scripts, specifically focusing on displaying a message when the 'Priority' field changes on an Incident form. It outlines the steps to create an onChange client script, including navigating to the Client Scripts section, filling in necessary fields, and entering the JavaScript code. The exercise concludes with a challenge to modify the script to display different messages based on the priority level set.

Uploaded by

skvumar1986
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Examples

This document provides a beginner's exercise for creating and using ServiceNow client scripts, specifically focusing on displaying a message when the 'Priority' field changes on an Incident form. It outlines the steps to create an onChange client script, including navigating to the Client Scripts section, filling in necessary fields, and entering the JavaScript code. The exercise concludes with a challenge to modify the script to display different messages based on the priority level set.

Uploaded by

skvumar1986
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Here’s an example exercise that introduces you to creating and using ServiceNow client

scripts. This exercise is designed for beginners and covers a common use case in ServiceNow
form development.

Exercise: Show a Field Message When a Priority Changes

Scenario

You want to notify the user every time the "Priority" field is changed on an Incident form by
displaying an informational message. This teaches you how to use an onChange client script.

Steps

1. Navigate to Client Scripts

• Go to System Definition → Client Scripts in the ServiceNow application


navigator.

2. Create a New Client Script

• Click New.

• Fill in the fields as follows:

• Name: Show Message on Priority Change

• Table: Incident [incident]

• UI Type: All

• Type: onChange

3. Configure the onChange Script

• Field name: priority

4. Enter the Script

• Copy and paste this JavaScript code into the Script field:

javascript

function onChange(control, oldValue, newValue, isLoading) {

if (isLoading || newValue == '') {

return;

g_form.showFieldMsg('priority', 'You have changed the priority. Please ensure your notes
are updated.', 'info');
}

5. Save the Script

• Click Submit or Update to save and activate the client script.

Test the Script

• Open any Incident record.

• Change the Priority field.

• You should see an informational message appear below the field when the value
changes.

Discussion

• This exercise demonstrates how to use an onChange client script to respond to user
actions in real time.

• You can modify the script to perform different actions, such as making fields
mandatory, showing/hiding fields, or adding validation messages.

Challenge:
Try modifying the script to display a warning message if the priority is set to "1 - Critical" and
only an info message for all other priorities.

Let me know if you’d like more advanced client script exercises or examples!

You might also like