Script examples

Now we've looked at some server- and client-side Glide classes, we can take a look at some examples of using these methods and properties in some slightly more complex blocks of code to achieve our goals in ServiceNow.

Let's start by having a look at some GlideRecord examples.

This time, we'll use GlideRecord multiple times, one inside another. This is a technique you will no doubt use quite often as you progress with your scripting. It has certainly served me well over the years.

In this example, we'll take a look at creating a problem record for every critical priority incident:

var incRec = new GlideRecord('incident');incRec.addQuery('priority', 1);incRec.query();while (incRec.next()) { //Critical incident found, create ...

Get Mastering ServiceNow Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.