"Processors", SRAPIs, and How to Run a Script and Redirect a User From a URL in ServiceNow

Processors in ServiceNow are (were) actually extremely useful things, though they’re surprisingly not very well-known. They give you a URL you can hit (like my_processor.do) and allow you to run a server-side script, then redirect the user to some other page.

Processors are quite useful for situations like generating a record and then redirecting the user to that record just by navigating to one URL, or - by adding some URL parameters (like my_processor.do?some_param=some_value) automating some simple or complex processes with nothing more than a single click of a URL! You can generate that URL dynamically and present it in the UI somewhere (for example, by using gs.addInfoMessage()), or link to the processor in an email. You could even use something like my “Set Catalog Variables from URL Parameters” tool in conjunction with this functionality to dynamically populate and submit RITMs from a single click of a link in a Knowledge Article!

Some pre-existing useful processors are:

  • System cache flush (cache.do)

  • Attachment processor for constructing and viewing attachments (sys_attachment.do)

  • Content search (content_search.do)

  • Customer service chat (CustomerServiceChat.do)

  • Export Wizard (export_wizard.do)

While it’s possible to modify the ACLs on the Processor table to allow you to create them again (for now), that may not be the best idea for long-term support.

So, if we don’t use a processor, how can we accomplish this functionality in our app? The answer is Scripted REST APIs (SRAPIs) plus a little bit of http header magic!

In this article, we’re going to show you how to accomplish (mostly) the same functionality as a processor using an SRAPI, and provide some code you can use to get your pseudo-processor SRAPI up-and-running within minutes! We’ll also provide some best-practice advice for how to use SRAPIs in this way, and outline some specific use-cases for this sort of thing.

Read more

SN Guys is now part of Jahnel Group!

It’s finally here! We’re thrilled to announce that The SN Guys (which runs SN Pro Tips)will be joining forces with our new parent company, Jahnel Group!
The Jahnel Group team is a passionate and dedicated group of over 100 software engineers with 20+ years of experience in the industry. Jahnel Group has worked closely with SN Guys for the past three years, and it’s been an exciting adventure to grow together. This new collaboration will allow our team to further deliver in the ServiceNow space and bring even more horsepower to our customers and community.

We look forward to starting out this new chapter together, to accomplish a bigger and better vision in the ServiceNow space and beyond.

More great stuff is coming soon. Don’t forget to subscribe to our newsletter, to stay informed!

Read more

Better ServiceNow Notifications (& Another FREE Tool!)

You’ve just implemented a new instance, process, catalog item, or workflow.
You put all that time and thought, and effort into making sure that everything that anyone could possibly want to know about, results in an email notification to all potentially-interested parties, so that nothing can possibly slip through the cracks!
And yet… somehow… you notice that users are still, often, not taking action where appropriate. Didn’t they get the email!?
You look through the email logs, and find that - indeed - among the sea of notifications that had been sent to them, there it is: the email telling them that they need to do something.

You: "Hey [approver], it looks like we've been waiting for you to approve this request for a couple of weeks now. Haven't you got any of the notification or reminder emails?"
Approver: "Uh... I have notifications from ServiceNow filtered to junk..."

Most of us have had some variation of this conversation.
Maybe they’ve filtered emails from ServiceNow to their junk folder. Maybe they’ve got a separate “special” folder just for SN emails, where they can be auto-routed and never looked at. Maybe they’ve just got so accustomed to 90% of the emails they get from ServiceNow being irrelevant or non-actionable for them, that they’ve got into the habit of just deleting them as soon as they show up.
The result is the same: your users aren’t getting your emails!

A notification that’s never read, is worse than no notification at all.


So, how do we stop this vicious cycle? -- Let’s talk about notifications in ServiceNow.

Read more

Debugging Client & Catalog Client Scripts in ServiceNow

When dealing with server-side scripts, the ServiceNow Debugger makes debugging relatively easy (most of the time), as you can actually see into the call stack, and the contents of your server-side variables as you step through your code, line-by-line. When available, that tool is incredibly useful; but unfortunately, it does not work with client scripts.

So, how do you troubleshoot client-side scripts in ServiceNow? Well, since those scripts execute inside the user’s browser, you’re going to have to use some browser-magic to make that happen. The good news is, modern browsers already have an incredible debugger that’s at least as good as the server-side script debugger in ServiceNow, built right in!

The question then becomes: “How do I trigger the client-side debugger? I can’t easily put breakpoints in my code that runs client-side, especially if it runs on-load; right?”
In fact, you can! Better yet, you can put calls to the debugger directly in your code!
In this short article, we’re going to see exactly how to do that, using a not-very-smart Client Script that runs on the Incident form. Join me after the jump, for a walk-through!

Read more

Getting Help from the ServiceNow Community

As I mention in my recent interview with Robert ‘The Duke’ Fedoruk (9:46), I truly believe that the highest calling of mankind is to learn, and then to teach.
I’m far from the only person in the ServiceNow developer community who feels this way! This fact is obviated by the incredible community of new and seasoned administrators, developers, and architects who are constantly trawling the community and just looking for ways that they can contribute.

That said, if you’ve spent much time in the community, you may have noticed that some questions go completely un-answered, while some elicit dozens of responses within the first hour; and some that receive dozens of responses, are mostly comprised of questions with no real answers.

This article aims to help explain why that is, and to help you ask better questions, more clearly, and get accurate help effectively. If you read this article carefully, you should come away with an understanding of:

  • What leg-work you’re expected to do, before asking a question

  • What information you need to provide in your question, in order for us to help

  • How to format your question so that it’s easy to read and understand

  • Some tips for phrasing your question in a way that makes it clear what you’re trying to do

If you see someone posting a question which doesn’t follow the guidelines mentioned in the Guide to Getting Help section of this article, link them to this article (gettinghelp.snc.guru) and tell them which rule they’ve violated!

Pro-tip: To link directly to the “Rules” section of this article, use rules.snc.guru.

Read more

Can ServiceNow Script Includes Use the "current" Variable?

Every once in a while, I look into the top search terms people have entered into Google or Bing (lol, who uses Bing?) that take them to this site. I do this to see if there are any common questions that people come here looking for answers to, but which I don’t yet have an article to answer. This month, that search term is “Can Script Includes use current”. This article aims to provide an answer to that question.

The question

I interpret the question “Can Script Includes use current” to mean:

If I write a function inside a Script Include (SI), and then call it from a Business Rule, can that function (in the SI) access the current object (from the Business Rule)?

Here’s an example SI which is attempting to do exactly that:

var CanIUseCurrent = Class.create();
CanIUseCurrent.prototype = {
    initialize: function() {},
    
    tryUsingCurrent: function() {
        gs.info('The current record\'s display value is: .', current.getDisplayValue());
        //^ This is bad!
    },
    
    type: 'CanIUseCurrent'
};

As you can see, the tryUsingCurrent() method is accessing a variable called current which is not declared or defined anywhere within the Script Include itself. Below, we’ll discuss whether this is possible, and whether it’s a good idea.

The short answer

The short answer to this question is: Yes, technically you can access anything that lives in the “calling” scope - but you shouldn’t. At least not without some extra steps to achieve “function purity”, which I’ll describe more in the long answer below.

If you take one thing from this article, let it be this:

Whenever possible, do not rely on “context” or the external/parent scope from which you expect your function to be called.
Never assume anything that you don’t have to, about any scope other than the function-scope you’re currently writing in.

Click below to read more, and see the full answer, including several important technical caveats!

Read more

Handling 'text/plain' and Other Unsupported Content Types in ServiceNow Scripted REST APIs

If you’ve ever tried to set up an AWS/SNS integration, you know that ServiceNow fails (rather spectacularly) to handle certain standard REST API request “Content-Types”; most notably, text/plain.

In this article, we’re going to discuss what happens when you you try to integrate with something that’s trying to send a plain-text payload, and how you can make it work. At the bottom of the article, we’ll have a simple Script Include that you can import into your instance to get around this issue, and make your plain-text integrations work.

To illustrate the issue, I’ll wake up my PDI, and set up a Scripted REST API (SRAPI) that’s meant to accept a plain-text payload. I’ll include the steps to set this up, in case you want to follow along in your own PDI.

First, in the Application Navigator, I’m going to open up…

Read more

Understanding Attachments in ServiceNow

This article was originally written in February 2016, but was last updated on 4/21/19.

Attachments in ServiceNow are not as straight-forward as email attachments, and it's not always obvious how to do what you want with them.

Recently, I needed to copy some attachments programmatically and otherwise fiddle around with attachments. After finding nothing in the ServiceNow product documentation, and very little through the usual search channels, I figured it was time to write an article about how to programmatically deal with attachments in ServiceNow. 

In this article, we'll learn how attachments really work in ServiceNow, how we can manipulate, copy, and even generate hashes for them (sometimes)! 

Read more

Using Custom Search Engines in Chrome to Quickly Navigate ServiceNow

How often have you wanted to do something like look up a record in a table by sys_id, look up a user by user_name, or jump straight to a table in ServiceNow just so you can run a query on it, but found yourself having to wait for the entire table to load, or having to navigate through several pages, waiting for each to load before you can get to the next?
For me, the answer is “multiple times, every single day”.

To that end, I’ve made this video on how to use custom Google Chrome search engines to make this process incredibly simple! Below the video, you’ll find some examples of useful “custom search engines” I’ve used in Chrome.

Click “Read more” to see the video, and some examples of how you can use this functionality!

Read more

Set Catalog Variables from URL Params (Free tool)

I've had this question come up over and over again in my career: "How do we populate variables on a catalog item or record producer, from the URL?" 

There are a couple of ways to do this, but often you'll see one-off solutions that require custom code for each and every catalog item, which also means that you have to know in advance, when designing the catalog item, what variables might be specified by URL, and how to populate them. 

I got tired of re-engineering the same basic solution over and over again, so I built a generalized tool. This tool adds to your system, a Variable Set. This variable set contains a catalog client script, but no actual variables (this is expected). The variable set is called “Parse sysparm_variables URI param”.

Once you’ve added the variable set to a given catalog item, you can populate any one or more variables in that catalog item, simply by manipulating the URL. Read on to learn more, or click here to jump straight to the tool/download page!

Read more