services
A holistic approach that accelerates your current vision while also making you future-proof. We help you face the future fluidically.

Digital Engineering

Value-driven and technology savvy. We future-proof your business.

Intelligent Enterprise

Helping you master your critical business applications, empowering your business to thrive.

Experience and Design

Harness the power of design to drive a whole new level of success.

Events and Webinars

Our Event Series

Sommelier

Turntable

Featured Event
14 - 16 May
Convention Centre Dublin, Ireland
Our Latest Talk
By Kanchan Ray, Dr. Sudipta Seal
video icon 60 mins
About
nagarro
Discover more about us,
an outstanding digital
solutions developer and a
great place to work in.
Investor
relations
Financial information,
governance, reports,
announcements, and
investor events.
News &
press releases
Catch up to what we are
doing, and what people
are talking about.
Caring &
sustainability
We care for our world.
Learn about our ESG
initiatives.

Fluidic
Enterprise

Beyond Agility, the convergence of technology and human ingenuity.
talk to us
Welcome to digital product engineering
Thanks for your interest. How can we help?
 
 
Author
Arif Mansuri
Arif Mansuri
connect

ServiceNow is a cloud-based platform that helps streamline and automate business processes by connecting people, systems, and departments. It offers a range of standard configurations, but you can extend the functionality of an instance using scripts. It uses industry-standard JavaScript to extend the functionality of an application. The platform is trusted by over 7,700 enterprise customers, which is anticipated only to grow. Hence, an understanding of JavaScript is essential to maximize the advantages of ServiceNow scripting.

While you can take courses to learn the JavaScript language, we are helping you brush up on your skills with some helpful pointers. This article lists tips and tricks to code accurately, effectively, and quickly, making managing your instance or developing new functionality no sweat. Read on to save time and effort, and boost your experience in development .

The common scripting challenges

Before we begin, let’s face the challenges!

While scripting we commonly use syntax, built-in function names, parameters, etc. There can be a fixed block of code that needs to be written in a specific format every time you do a specific task, e.g., when querying a table.

Manually typing the same line of code repeatedly can be time-consuming, tedious, and erroneous. Furthermore, it is difficult to remember the available out-of-the-box functions, classes, and syntax of each function call.

Let’s see how  to overcome these challenges.

7 ServiceNow quick scripting tips & tricks

Our task is to call a Scriptinclude function in the client script, where we have a fixed syntax. We must write at least 10 lines of code every time to call the Scriptinclude function. Instead, we can write it once (Create a Syntax Editor Macros Record) and call it whenever required using a few key combinations. Let’s now understand how to do it!

Here are some out-of-the-box features in the ServiceNow scripting section:

1. Syntax Editor Macros

Syntax Editor Macros are code shortcuts for typing commonly used code. You can create Macros in ServiceNow to automatically create code blocks while in a script editor.

Following are the examples of OOB syntax editor Macros.

a. Glide Record

The GlideRecord class is used to interact with the ServiceNow database from a script. You can simply type “vargr” and hit the Tab key, creating a code block for obtaining a GlideRecord.

ServiceNow-scripting-1ServiceNow-scripting-2

b. Glide Record with OR query

You can type “gror” and hit the Tab key. This will create the code block for obtaining a GlideRecord with “OR” query.

ServiceNow-scripting-3ServiceNow-scripting-4

c. For Loop

The For Loop function helps specify iteration in executing a code block, multiple times. You can type “for” and hit the Tab key. This will create the code block of “for” Loop.

ServiceNow-scripting-5ServiceNow-scripting-6

d. Info Message

The addInfoMessage is used to add any message for customers, such as alerts, info, or error messages. You can type “info” and hit the Tab key. This will create the code for adding the info message.

ServiceNow-scripting-7ServiceNow-scripting-8

e. Documentation Header

You can type “doc” and hit the Tab key. This will create the Documentation Header.

ServiceNow-scripting-9ServiceNow-scripting-10

f. Method

You can type “method” and hit the Tab key. This will create Standard JavaScript Class Method.

ServiceNow-scripting-11ServiceNow-scripting-12

g. List of available Syntax Editor Macros

If you want to check the list of available Syntax Editors, type “help” and press the Tab key. A list of Macros with its description will be displayed.

ServiceNow-scripting-13ServiceNow-scripting-14

h. Create Custom Macros

You can create your own macros under “System Definition -> Syntax Editor Macros” module. Click on “New” button.

Syntax-editor-macros

Create-custom-macros

Glide Ajax Example:

Fill in the details as provided in the screenshot below and save the record.

Glide-ajax

To test the previously created macro, type “ga” in the scripting section and press the Tab key to get the Glide Ajax code block.

Ajax-1

Ajax-2

2. Scripting Assistance

While scripting, if you need a suggestion list from ServiceNow, then type in the initial letters and press CTRL + Spacebar.

Scripting-assistance

3. Class Description

To know about any built-in classes, press Ctrl + J.

Class-description

4. Help

Click on the “?” icon or press Ctrl + H for a list of keyboard shortcuts to improve your coding experience.

Help-1help-2

5. Pre-filter large table list view data loads

Loading the default list view can take a long time or fail to load if you have a massive table in the system (with millions of rows like Syslog). If you need specific data in a large table, open the filter view to pre-filter data before making queries.

To load the filter view for a table, you would type the following into your browser’s URL navigator: https://INSTANCE.service-now.com/TABLENAME_list.do?sysparm_filter_only=true

Example:

https://dev103951.service-now.com/syslog_list.do?sysparm_filter_only=true

Empty logs form will be loaded to create the required filter.

Empty-logs

Create the required filter and click on “run” button to populate the required data.

run-button-1run-button-2

6. All configurations on a specific table

To check all the configurations (Scripts, UI Policies, ACLs, Dictionary entries, etc.) for a specific table, type “tablename.config” in the filter navigator and hit the Enter key.

For example:

To check all the configurations on the incident table, type “incident.config” in the filter navigator and hit Enter key.

Incident-configIncident-config-2

7. JavaScript Executor

JavaScript executor is the equivalent of Background Scripts, but for the client-side codes.

Press Ctrl + Alt + Shift + J to open the script Editor. Type your code and click on the execute code button.

For example: If you want to check the back-end value of the current state field, then instead of checking for the choice list, you can check as given in the screenshot below:

Java-scriptJava-script-1

 

You can make the most of the powerful ServiceNow platform with scripting and knowing a few hacks to write lines of coding required on a daily basis is always a good idea. We hope you find these tricks interesting and helpful.

Curious to start your journey with ServiceNow? We can help!