Skip to Main Content
Mastering ServiceNow Scripting
book

Mastering ServiceNow Scripting

by Andrew Kindred
February 2018
Intermediate to advanced content levelIntermediate to advanced
226 pages
5h 13m
English
Packt Publishing
Content preview from Mastering ServiceNow Scripting

Script examples

Having introduced the basic elements of client-side scripting and how and where to use it, we can take a look at some examples of scripts to further our understanding.

We'll start by looking at some client script examples.

In this first example, we'll use an onLoad client script to show and hide form sections based on the logged-in users' roles. We'll only show the related records form section on the incident form if the logged-in user has the itil_admin role:

function onLoad() {    if (g_user.hasRole('itil_admin')) {        g_form.setSectionDisplay('related_records', false);    }}

As you can see in the example, we are using g_user's hasRole method to determine whether the logged-in user has the required role. If they don't, then we use ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PowerShell Cookbook, 4th Edition

PowerShell Cookbook, 4th Edition

Lee Holmes
Learning Splunk

Learning Splunk

Tom Kopchak

Publisher Resources

ISBN: 9781788627092Supplemental Content