SN101: Boolean logic and ServiceNow's Condition Builder

This article is part one of a multi-part series called "SN101", in which we'll explore some of the basic functionality of ServiceNow in beautiful detail. While the "SN101" articles are aimed toward newcomers to the ServiceNow platform, or new JavaScript developers, there is very likely to be something for everyone in each article. Thus, even if you are an experienced developer, it is recommended that you read the SN101 articles in chronological order.

Let's talk about building queries in ServiceNow...

See the whole article including some pretty awful puns, after the jump.

Read More

Locate any record in any table, by sys_id in ServiceNow

Dozens of times, I've seen hard-coded sys_ids in scripts or system properties, and wanted to know what record they correspond to. Unfortunately, there isn't really a good way to do this without knowing what table the sys_id is in!
The global search box only supports searching by sys_id on tables for which that is specifically enabled, so the only solution for this has often been to scour script after script, digging down until I find where the sys_id is actually used, and try to decipher what table it corresponds to. Well, today I decided - "Enough is enough" - and I wrote a script to check each table for me. I was surprised at the ease with which I was able to accomplish my goal, as well as the speed and simplicity of the script.

Read More

Detecting Duplicate Records with GlideAggregate

Let's say you're working for a company who has just acquired another company, and you've just imported all of the users from the acquired company's User (sys_user) table.
Unfortunately, you realize just a second too late, that their user database contains some of the same people as are already in your database - for example, some executives had accounts in both services.
Or maybe you were previously running the instance without enforcing number uniqueness on the incident table for some reason, and you want to change that.

The first step to resolving these issues, is detecting duplicate records, based on a given field. Here's a simple script include that will do that for you:

Read More

Array.indexOf() not working in ServiceNow - Solution!

I'm baffled that this little issue has never cropped up for me until now, but I recently discovered a little annoyance in ServiceNow while iterating through an array. This issue had me going round in circles for hours, so hopefully by sharing my findings with our readers, I can spare some folks the frustration I felt.

First, I'll tell you a little story about how it happened to me, and then I'll tell you the explanation for this odd behavior.

Read More

Understanding Dynamic Filters & Checking a Record Against a Filter Using GlideFilter

I recently found myself in a situation where I had to check if a given record (the 'current' object in my case) matched a filter associated with another record (a client script, in my case). If you find yourself needing to do something similar, it might help you to know about an undocumented Glide API called "GlideFilter".

GlideFilter takes two arguments: 

  1. A glide record containing the record you'd like to check
  2. The query string (aka "encoded query") you'd like to check it against. 

The first argument may be self-explanatory - it's a GlideRecord object containing a single record.
The second argument, if you're not familiar with encoded queries, is a string of text that represents a query. If you've ever built a query in a condition builder, you've built an encoded query.

Read More

Bookmarklet: Load the current page in the ServiceNow frame

I often find myself middle-clicking a link or otherwise opening links in ServiceNow in a "new tab" or "new window". This means that I often get pages that load just the content frame, without the ServiceNow frame.

ServiceNow content frame without banner or application navigator

The frame is the header and side-bar that facilitate easy navigation around ServiceNow, and often times I find that I don't need it. However, when I'm in a tab and don't want to lose my place, but I do want to get the sidebar back, I'm pretty much out of luck. My options then, are to either manually modify the URL with some weird string I can never remember, or to go back to my main ServiceNow instance home page and start from scratch.

Wouldn't it be nice if there was an easier way to load the current page in the ServiceNow frame?
I think so too, so I wrote this little bookmarklet.

ServiceNow Frame

Click and drag that link up to your bookmarks bar or wherever you'd like to save it, and you'll have a handy little button that you can click to load whatever page you're on in ServiceNow, in the SN frame. 

Easily Clone One User's Access to Another User

If you're a ServiceNow Admin, chances are you get lots of tickets from people asking you to grant or revoke access to this or that.
Sure, onboarding and offboarding, and some basic permissions work, can be automated -- but sometimes you just don't have a catalog item for what the user is requesting, so you have to do it manually.


So if you're like me, you get these tickets all the time: 

"Jerry doesn't have access to the same applications as the rest of our team. Please add him to whatever groups he requires to do his job. Nerd." 

Unless you're intimately familiar with Jerry's job, you're going to need some more information to go off of. I normally ask for the ID of another user whose access I can clone, and then open each profile on a separate monitor and go through each group one at a time. I once did 77 groups this way, for two separate users. It was a nightmare...

Read More