- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2019 07:20 AM
I am new to ServiceNow but I have been asked to prepopulate a catalog item's variables from a URL that is passed to the end user in an email. From my searches on the ServiceNow community, I came across two helpful articles and followed their guidance:
3 Ways to Populate Values via URL and Populating Values through Service Portal
But for some reason, I cannot get my variables to appear on the form. I am trying to pass only 3 variables - requested for, expiration date, and comments. Below is my client script, set with 'onLoad', and the URL I am using. The image is a screenshot of my catalog item I am trying to populate. Any assistance here would be greatly appreciated.
https://<instance>.service-now.com/nav_to.do?uri=com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=d0431cdddbe22e004db470d9af9619ef&sysparm_requestedfor=e7dcc734db612300177bab8b4b961961&sysparm_expdte=03202019&sysparm_comments=TEST
function onLoad() {
//Use the 'getParameterValue' function below to get the parameter values from the URL
var requested_for = getParameterValue('sysparm_requestedfor');
var requestedfor = g_form.getReference('requested_for').requested_for;
var comments = decodeURI(getParameterValue('sysparm_comments'));
var expdate = decodeURI(getParameterValue('sysparm_expdte'));
if (requested_for) {
g_form.setValue('requested_for', requestedfor);
}
if (comments) {
g_form.setValue('sc_all_items_notes', comments);
}
if (expdate) {
g_form.setValue('new_expiration_date', new GlideDateTime(expdate));//date_variable
}
}
function getParameterValue(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(top.location);
if (results == null) {
return "";
} else {
return unescape(results[1]);
}
}
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2019 06:38 AM
I don't think getParameterValue works anymore. We tried using that long ago and had to switch to GlideURL.
What happens if you paste this url into your browser and click enter: https://<instance>.service-now.com/nav_to.do?uri=com.glideapp.servicecatalog_cat_item_view.do?syspar...
a) does the catalog item open? if yes, we know sysparm_id is working
b) if the catalog item opens, copy the URL from your browser. Does it match what you entered or is it truncated? If it matches, the URL is working, just need to fix the client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2019 09:39 AM
I entered the URL and updated to my instance. Also, updated the code you provided to make sure it was using "getParam" and not "getParameterValue". So after that and updating one of the '&' in the URL, it worked!!!! Thank you so very much!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2019 09:43 AM
Nice work!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2022 12:46 AM
Hi Colleen - sorry to bring up an old post! Do you have the final iteration of this solution to hand please? We've got a similar requirement where product teams would like to have a catalog item prepopulate them as the assignment group.
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2019 11:07 AM
Michael,
You greatly helped with the populating of the variables from a URL but for some reason the new expiration date value is not storing what is passed in but the other two fields are. It is defaulting to today's date? From what I have read online, the date fields in ServiceNow can be quite picky. Below is my dilemma:
Here is the URL that I am testing with and is currently pulling the values onto the form (screenshot below).
I do not touch any of the fields they are what I want so I click submit. When I do, here is the RITM record:
Here is my code from the Catalog Client Script that is running. It populates all 3 variables but the date is not sticking? BUT if I update the pre-populated date with a new date value, it stores it then??
function onLoad() {
var User = getParameterValue('sysparm_requestedfor');
var usr = new GlideAjax('FindRequestedFor');
usr.addParam('sysparm_name', 'getRequestedFor');
usr.addParam('sysparm_user', User);
usr.getXML(getUserParse);
function getUserParse(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if(User != undefined || User != '') g_form.setValue('requested_for', answer);
}
var Date = getParameterValue('sysparm_expdte');
var comments = getParameterValue('sysparm_comments');
if(Date != undefined || Date != '') g_form.setValue('new_expiration_date', Date);
if(comments != undefined || comments != '') g_form.setValue('sc_all_items_notes', comments);
}
function getParameterValue(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(top.location);
if (results == null) {
return "";
} else {
return unescape(results[1]);
}
}
Any assistance would be greatly appreciated. This last thing is preventing me from migrating my code to Production.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2022 11:04 PM
auto populate URL of selected RITM in one more catalog item