Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering ServiceNow Scripting

You're reading from   Mastering ServiceNow Scripting Leverage JavaScript APIs to perform client-side and server-side scripting on ServiceNow instances

Arrow left icon
Product type Paperback
Published in Feb 2018
Publisher Packt
ISBN-13 9781788627092
Length 226 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Andrew Kindred Andrew Kindred
Author Profile Icon Andrew Kindred
Andrew Kindred
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Getting Started FREE CHAPTER 2. Exploring the ServiceNow Glide Class 3. Introduction to Client-Side Scripting 4. Advanced Client-Side Scripting 5. Introduction to Server-Side Scripting 6. Advanced Server-Side Scripting 7. Introduction to Custom Pages 8. Scripting with Jelly 9. Debugging the Script 10. Best Practices 11. Deployments with the Update Sets 12. Building a Custom Application Using ServiceNow Scripting 13. Other Books You May Enjoy

Introduction to scripting

ServiceNow uses JavaScript as a language for the majority of the scripts you can write or edit. If you already have a background in JavaScript, then you will certainly have a head start when it comes to writing your first scripts. The JavaScript engine used for writing scripts is updated as new versions of ServiceNow are released. The other language used is called Jelly. Not many people outside of the ServiceNow space are aware of Jelly, and it certainly wasn't a language I was familiar with before working with ServiceNow. Fortunately, Jelly is not used in the majority of scripts, and we'll cover how and where to use it in a later chapter.

Before you start writing your first script, it is important to check whether your goal can be achieved without using script. This should always be a consideration before you get started. By leveraging configurations in the form of UI policies, for example, it is possible to avoid customization all together.  

When scripting, it is important to think about what you want to achieve, and which records and what fields in the database you will need access to. The most common scripts will simply need information from the current record being displayed or updated, but more complex scripts may need to access data from several different tables. It is a good practice to ensure that the database and table structure will allow you to get all the data you need for your script from the current record before you start.

One other point to note when scripting is to make sure your code is well documented, including good comments and descriptions of what goals are to be achieved. While you are writing code, it can seem that what it does will be obvious, but coming back to the same code after some time, that often will not be the case. Maintaining ServiceNow instances is a big part of an administrator's job, and trying to do this with no comments in scripts can be a laborious task. I have come across many instances with insufficient comments and descriptions, and a lot of time is initially wasted on discovering how it all hangs together. Documenting your code will not only help you over time, but will also help any other administrators who need to maintain your scripts and instances.

For example, it is important to explain what each function does:

/*This function returns true or false based on the whether the input variable is 0
Inputs: input - integer
*/
function myFunction(input) {
if (input == 0) {
return true;
} else {
return false;
}
}

Most scripts will use the glide classes provided by ServiceNow, which we will discuss in the next chapter.

You have been reading a chapter from
Mastering ServiceNow Scripting
Published in: Feb 2018
Publisher: Packt
ISBN-13: 9781788627092
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image