
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
One of the most common questions that I see on the ServiceNow community is some variation of "How do I populate values on my form via the URL?" There are many circumstances where you already have values for some fields/variables and you're sending a form to someone to fill out whether redirecting there or through email. In those cases you don't want to make your user go find that information or even have to enter it into the form if it's already available. There are three main areas in ServiceNow where this is most commonly done:
- A table form (Incident, Facilities, etc.)
- A Catalog Item, Record Producer, or Order Guide
- A UI Page/CMS Page
The documentation is all out there already, but I thought I'd pull it all together in one place.
Table Form
One of my favorite docs articles is called Navigating by URL and does a really good job explaining how to build a url that will prepopulate values on a form. The basic anatomy of the url is:
https://<instance name>.service-now.com/nav_to.do?uri=incident.do?sys_id=-1%26sysparm_query=caller_id=2809952237b1300054b6a3549dbe5dd4
incident — this is the name of the table you're redirecting to
sys_id=-1 — passing negative one as the sys_id tells ServiceNow you're opening a new record
sysparm_query — this is the parameter where you will set your values
caller_id=2809952237b1300054b6a3549dbe5dd4 — this is the encoded query you will use to set the caller to a specific indivdual
Catalog
Setting a value via URL requires a little more work in a catalog item/record producer, but luckily there's a really great SNCGuru article called Parse URL Parameters in a Client Script that I've use many, many times to accomplish this.
For this method, you add some sort of parameter to the end of the url of the catalog item. In this case, you can pass the sys_id of a user with the sysparm_user parameter:
https://<instance name>.service-now.com/nav_to.do?uri=com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=d65394f54ff2520020af09fd0210c759&sysparm_user=2809952237b1300054b6a3549dbe5dd4
Now that you've passed it you have to use an onload client script on the catalog item itself to consume that parameter and most likely set a value with it like this:
function onLoad() {
//Use the 'getParameterValue' function below to get the parameter values from the URL
var user = getParameterValue('sysparm_user');
if (user) {
g_form.setValue('user_variable', user);
}
}
function getParameterValue(name) {
var url = document.URL.parseQuery();
if (url[name]) {
return decodeURI(url[name]);
} else {
return;
}
}
NOTE: This script looks a little different if you want to use it through the Service Portal as document and prototype will not work there. Check out the updated script here.
UI Page
The third place you might want to pass a url parameter would be a ui page. UI Pages in ServiceNow are custom pages built using jelly. The wiki article in this case isn't quite as informative, and it's called Extensions to Jelly Syntax. In this scenario, if you wanted to pass a user sys_id to the jelly in the page, you could do:
https://<instance name>.service-now.com/fancy_user_page.do?sysparm_user=2809952237b1300054b6a3549dbe5dd4
Then in jelly you can do something like:
<j:set var="jvar_user_sysid" value="${RP.getParameterValue('sysparm_user')}">
Then you can use that jelly variable later on in your UI Page.
Hope this post was helpful, and I'll be following up later with how to pass a url parameter into an angular based UI Page.
- 118,549 Views
- « Previous
-
- 1
- 4
- 5
- 6
- 7
- Next »
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.