
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 03-27-2018 08:40 PM
Hi Everyone!
A few weeks after our Go-Live of ServiceNow I received a request from someone on our Service Desk to think about a TinyURL-Like service for sharing links to tickets across our organisation. While it works to just copy/paste the ugly URL that is generated when you go to an Incident, in some circumstances a human-readable link is nicer (Company communications, chat windows, talking to people who may not trust illegible URLs, generally understanding where you are going to land if you click the link)
After some digging through Community (sources at the bottom) and not coming up with a lot of help, I was able to use a Processor and some UI Actions to accomplish what I think is a fairly elegant solution. I'm sharing it here to help anyone with a similar request.
Step 1: Write a processor
As I was looking to make this work across a few tables (Incident, Request, Request Item) I would have liked to make my code more reusable, but including the table as a parameter was again undermining the whole idea of a "short URL". Here is my solution:
URL Format:
https://<instance>.service-now.com/short_url.do?tsknum=INC0000123
following your standard number schemes & very readable!
Type: Script
Parameters: "tsknum"
Path: "short_url"
Script:
(function process(g_request, g_response, g_processor) {
//Get the parameter
var taskparam = g_request.getParameter("tsknum");
var sysid = '';
// If it's an incident
if (taskparam.toLowerCase().includes("inc")) {
var gr = new GlideRecord("incident");
gr.addQuery("number",taskparam);
gr.query();
if (gr.next()) {
sysid = gr.getUniqueValue();
g_processor.redirect("/nav_to.do?uri=/incident.do%3Fsys_id%3D" + sysid);
//For troubleshooting / testing, swap the above line with this one:
//g_processor.writeOutput("Found Incident: " + gr.getUniqueValue());
} else {
g_processor.redirect("/navpage.do");
g_processor.writeOutput("No Incident Found");
}
// If it's a request
} else if (taskparam.toLowerCase().includes("req")) {
var grReq = new GlideRecord("sc_request");
grReq.addQuery("number",taskparam);
grReq.query();
if (grReq.next()) {
sysid = grReq.getUniqueValue();
g_processor.redirect("/nav_to.do?uri=/sc_request.do%3Fsys_id%3D" + sysid + "%26sysparm_view=my_request");
//g_processor.writeOutput("Found Incident: " + gr.getUniqueValue());
} else {
g_processor.redirect("/navpage.do");
g_processor.writeOutput("No Request Found");
}
// Finally, if it's a Request Item
} else if (taskparam.toLowerCase().includes("ritm")) {
var grRitm = new GlideRecord("sc_req_item");
grRitm.addQuery("number",taskparam);
grRitm.query();
if (grRitm.next()) {
sysid = grRitm.getUniqueValue();
g_processor.redirect("/nav_to.do?uri=/sc_req_item.do%3Fsys_id%3D" + sysid + "%26sysparm_view=my_request");
//g_processor.writeOutput("Found Incident: " + gr.getUniqueValue());
} else {
//redirect to homepage if it doesn't match
g_processor.redirect("/navpage.do");
g_processor.writeOutput("No Request Item Found");
}
} else {
//Generic catchall redirect to homepage
g_processor.redirect("/navpage.do");
}
})(g_request, g_response, g_processor);
I know the above has some limitations, like no handling of two records with the same "number" - but I'm OK with this. For a normal OOTB implementation it should work nicely.
Step 2: Create UI action(s)
For our Service Desk friend to be able to access this action easily, it should be accessable on the forms of the tasks they are using. In my implementation, I'll create three actions on incident, sc_request, and sc_req_item tables. As these all extend the Task table, the number field is compatible!
Name: Copy ShortLink
Table: <as above>
Show Update: True
Client: True
Form Button/Context/Link: <your choice. I used Context Menu>
Onclick: getShortLink();
This is the function we are going to write and call when the user clicks the action
Script:
function getShortLink() {
var instance = window.location.hostname + "/";
var shortUrl = g_form.getValue('number');
window.prompt("Copy to clipboard: Ctrl+C, Enter", instance + "short_url.do?tsknum=" + shortUrl);
}
Very simply, the script gets the current domain (so it'll work in all your environments) and formats the URL with the current number field, then presents it to the user in a prompt pre-selected for quick copy/paste. Neat!
Here's the end result:
And the popup:
I hope this helps another admin somewhere along the line!
-Andrew
References:
Constructing Tiny URLs by rickseiden(infosys)
Processor Redirects (SN Docs / API)
UI Action - Copy certain fields to the clipboard by Brad Tilton
- 4,097 Views

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Could you do this also for KB articles?

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Joe,
I don't see why not. You would have to think about how you want them to be accessed, through a Service Portal or in-platform, and build your script from there.
Let me know how you go!

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Because processors are deprecated in Paris, I was curious if there is a way to accomplish this using the supported feature of Scripted REST APIs. We have yet to deploy to production, and we don't want to start down a path using a deprecated feature (processors), if possible.
Our use case is that we have published and marketed many short URLs in our current environment, pre-ServiceNow (e.g. https://askit.ttu.edu/phishingexamples). They are much simpler for customers to type, agents can remember them easily, and they are guessable. Most of them link to common KB solutions, while a few redirect to a website of our choice. We need all of these existing URLs to continue working when we move to ServiceNow. This askit.ttu.edu hostname will be our service portal address in ServiceNow.
Our current environment accomplishes this using Tomcat URL rewrite rules.
We plan to use the custom URL feature for our ServiceNow instance so that we keep the host name the same, and for the exact paths the solution at https://community.servicenow.com/community?id=community_question&sys_id=01e3cfa5dbd8dbc01dcaf3231f96... was tested by us and works great.
From reviewing the documentation about Scripted REST APIs, it seems like we don't have full control over the exact URL.
Can anyone help with this?