ServiceNow Developers: BE THE GUIDE!

Every ServiceNow developer, administrator, and architect has at one time or another, got a requirement from their client that they know is bad-practice, silly, or sub-optimal.

I often come across developers in the ServiceNow communities (such as the ServiceNow Developer forums, Discord, or Telegram groups), having conversations like this:

How do I do X?
Why would you want to do that? What’s the goal?
Because that’s the requirement from the client.

Even when told that what they want to do is technically impossible, some will refuse to go back to the client and tell them that.
It’s as if people sometimes can’t fathom telling a client “that’s not possible but, if you tell me why you want to do it, I might be able to find a better way”.

In this article, we discuss how to approach these situations and what it means to be the guide as a ServiceNow developer.

Read more

A Faster, More Efficient Client-side GlideRecord (Free tool!)

EfficientGlideRecord is a client-side API class from which you can perform asynchronous client-side GlideRecord-style queries while maximizing performance (eliminating the negative performance impact of using the client-side GlideRecord object) and without having to create a separate GlideAjax Script Include!

Every senior ServiceNow developer knows that client-side GlideRecord queries are slow and inefficient, and that it's far preferable to use a GlideAjax call. However, GlideAjax can be a REAL pain to implement. I've got an entire article about using GlideAjax from both a client and server perspective.
Even I have to look up my own article from time to time to remind myself of the correct patterns when I need to use it, and I groan every time I think about having to create yet another Script Include just to handle this one little use-case in this unique application scope or something.

A couple days ago, I was whingeing on the ServiceNow Developers Discord about the poor performance (and inaccurate documentation) of the client-side GlideRecord API.
I was wishing there was something better that didn’t require me to make a whole separate Script Include just to query a single record from the database and get the value of a few fields on that record in my Client Script.

Unfortunately, that’s just the way it is. Client-side GlideRecord is massively inefficient, far too slow, and returns way too much unnecessary data to be used commonly in production code. GlideAjax is simply the best and most efficient method for looking up data from client-side scripts.

At least, it wasuntil now!

After searching for a better solution for another couple of hours, I finally decided:

So, I did. And now I’m sharing that solution with you!

This consists of only a few files: A client-callable Script Include that does the back-end work for us, and a Global UI Script that acts as the client-side GlideRecord alternative (which I very creatively named EfficientGlideRecord). There is also a "portal" version of the same UI Script.

Aside from the fact that you'll specify only the fields you want to retrieve from the database for maximum performance (see examples in the API documentation), this is otherwise a near-perfect drop-in replacement for the client-side GlideRecord class; meaning that in the vast majority of cases, you'll be able to take your existing code, change the word "GlideRecord" to "EfficientGlideRecord", call .addField() for each field you want to retrieve, and that's it - you're done!

You might be wondering: "Okay, that's not too much work. I could do a code search for client-side code calling GlideRecord and get a performance and user-experience boost by replacing it with EfficientGlideRecord and adding any fields referenced in the callback function... but just how much performance improvement are we talking about here? Is it actually worth it?"

Oh my sweet summer child... even I was baffled when I did my performance testing, at just how inefficient the client-side GlideRecord is, and by just how much performance could be improved with EfficientGlideRecord.

As you can see in the Performance section (or in the image below), with the fastest internet, performance was improved by 80% (from nearly three full seconds, down to about half a second). For larger queries by users with a slower 1-10Mbps internet connection, performance was improved by as much as 93% - from ~71,700 milliseconds, down to ~5,100ms.

Read on to learn more, see usage examples, and download this free tool as an Update Set!

Read more (+ full API documentation)

Animated Loading Message & Collapsible Details on ServiceNow Form or Field (Client-side)

I recently found myself in a bit of a sticky pickle in ServiceNow. I was building a client-side UI Action which needed to call a Script Include via GlideAjax.
The server-side component of that script would then call a REST API and retrieve some data.
The data would be transformed and then returned to the client to be displayed in the form.

This caused two major issues:

  1. The response could take a while, so it looks for several seconds as though clicking the button did nothing.

  2. When the response did arrive, there could potentially be a lot of data to display in the form message.

As you can see in the gif above, I was able to solve both issues with a fancy bit of code. And now I’m gonna share that code with you! How magnanimous, right? Right?!?

This article will tell you how I solved them, and provide you with the code I used (made fully modular so you can customize its behavior for your own situation). You can then include those functions in your Client Script in order to achieve similar functionality, with only a couple of lines of code!

Read more

Using .addJoinQuery() & How to Query Records with Attachments in ServiceNow

Here’s a common question:

“How do I use a scripted GlideRecord query to get all records in a given table that have attachments?”

Often, people in the Community Forums will suggest querying the table, iterating through every single record, running .hasAttachment() on every single one, and adding those records to a list if that returns true.

Or, they might suggest querying the sys_attachment table, querying every attachment associated with the target table, pushing every unique value from the attachment record's `table_sys_id` field into an array, then using that array to query the target table with something like grMyRecord.addQuery('sys_id', 'IN', arrRecordsWithAttachments.join(','));.

However, these solutions are quite slow and not exactly ideal. Instead, consider the use of GlideRecord's .addJoinQuery() method.

Consider the following code…

Read more

Free, Simple URL Shortener for ServiceNow Nerds (snc.guru)

🛠️That’s right folks, it's yet another FREE ServiceNow tool on SN Pro Tips!🔧

This one is a URL Shortener that uses the fancy-fun-fresh "snc.guru" domain, so you can look like a really heckin' hoopy frood when you share a link to your blog post, a resource you found, etc.

Create short, memorable, easy quick-links with the easy-to-remember pattern: go.snc.guru/your_thing
Start creating your own custom ServiceNow-ey short-URLs with snc.guru with just a few clicks. Head over to short.snc.guru, or click “Read more” to use what might be the world’s simplest URL shortener!

Read more

How to Get and Parse ServiceNow Journal Entries as Strings/HTML

I come across this question all the time in the ServiceNow community forums, and in the ServiceNow developer community Discord, Slack, and Telegram groups.

“How do I get the last N journal entries from a record in ServiceNow, in a script?”
“How do I print the last N journal entries in my notification email or mail script in ServiceNow?”
“How do I parse journal entries for HTML so special characters and line-breaks will show up properly in HTML or an email?”

I’ve helped people create so many one-off solutions to these questions that it felt more efficient to, finally, just create a single function that can do it all!

Click below to be taken to the article, and get the free tool that you can add your instance!

Read more

New tool: Get Latest Version of ServiceNow Docs Page

Imagine you’re searching for an issue you’re researching in ServiceNow, and the first result you find on Google is a ServiceNow documentation page… from the Jakarta version of ServiceNow. It’s totally out of date.

How do you make sure that you’re getting the latest version of this same page in the documentation?
And what if you want to share the link to the latest version of that doc with someone else?
What if, for example, you’re posting to the community forums and you want to make sure that the link you post will always go to the latest version of that doc, even if someone sees the link years later?

With this extension (or bookmarklet script), you can be on any ServiceNow Docs page and simply click one button to (1) have the URL of the latest version of that article copied to your clipboard, and (2) be redirected to the latest version of that page.
The best thing about that generated link is that even if you were to navigate to it again years later, it would still take you to the latest version of that page, even if the “latest version” is newer than the version that was the latest when you generated the link!

Read more

How to Set or Change ServiceNow Application's Repository URL, Credentials, or SSH Key

Unfortunately, ServiceNow has made the interesting (see: baffling) decision to make it confoundingly difficult to figure out how to change the Git repo your application is associated with, once it’s been linked to one. I can’t fathom why they might’ve done this, but that is unfortunately not an unusual sentiment when it comes to ServiceNow.

Knowing that I’m liable to let this article devolve into a 10-page ranting, rambling manifesto lamenting the unnecessarily opaque and undocumented process for doing basic things like changing the repo your application is associated with, let’s instead get straight on in to how to do it anyway.

Generating an SSH Key

If you haven’t already got one set up (such as if your new repo is associated to a new Github account), you’ll need to first generate an SSH public/private key pair. This will allow your ServiceNow instance to authenticate to your your Github account and repositories.

  1. Using a tool such as this one, enter a passphrase and click Generate-SSH-Keys. Save the Public and Private keys somewhere temporarily, and don't forget the passphrase! You’ll need all three of these in a bit.

  2. From Github, click your profile icon and go to Settings

Read more

How to return a CSV file from a Scripted REST API (SRAPI) in ServiceNow

I recently dealt with a requirement whereby I needed to export only certain columns from records on a given table that match a given query, to a CSV file.

No problem”, I said; “that’s easy. You just add ‘?CSV’ to the end of the table URL.

Oh, but it’s never that easy, is it? In this case, there were a few odd stipulations:

  • The header names need to be specific strings (not the same as their column names in ServiceNow)

  • Some of the columns need to have calculated or static values; values not in ServiceNow (and we don’t want to make calculated columns for them)

  • The endpoint must not return CSV data embedded in a JSON response body, but must actually return a CSV file. Or to put it more precisely, the endpoint URL must resolve to a CSV file.

Because of the nature of this requirement, I was going to need to create a Scripted REST API (SRAPI); so I did…

Click below to read more!

Read more