- 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-04-2019 06:31 AM
Let's back up. Can you explain exactly what you're trying to do?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2019 06:44 AM
I am running a Powershell script against our AD to identify any contractor's who account will expire in 30 days. Once someone is identified, their manager would receive an email as a heads up to either extend it or let it expire. The email is to contain a hyperlink containing the catalog item, requested for (contractor), expiration date and comments. This would allow the manager to click the link and be taken to our catalog item for 'update employee or contractor end dates' being pre-populated with the 3 variables.
So, I have the catalog item created along with the client catalog script. I have the URL and it brings up the page, screenshot above but for some reason it is not 'translating' the variables to be displayed. The Requested For field is a Reference field mapped to "sysparm_requestedfor", the New Expiration Date is a date field mapped to "sysparm_expdte" and the Additional notes is a string field mapped to "sysparm_comments". My apologies for not clarifying this earlier.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2019 02:01 PM
I took your original url code and tried to use it in my dev site with an out of box catalog item without luck. Then I changed "&" to %26 with the code I sent and it worked fine, the user populated. So try changing your URL to something like this:
nav_to.do?uri=com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=d0431cdddbe22e004db470d9af9619ef%26sysparm_requestedfor=e7dcc734db612300177bab8b4b961961&sysparm_expdte=03202019%26sysparm_comments=TEST
if it doesn't work, copy the URL and see if it contains all of the parameters. My first few runs only the ID existed, that's how I figured out the "&" signs weren't working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2019 06:27 AM
Thank you for your reply. I tried replacing the '&' with '%26' with your code and it still will not display. If I use simply "g_form.setValue('cnt_requested_for', 'e7dcc734db612300177bab8b4b961961');" as the first line after "function onLoad()", it works. I believe it has to do with the 'getParameterValue' function. I put alert statements after each step and the comments, date, and requested (shown below) and the 'results' for each one come back as null? I tried this with '&' and with '%26'. If this logic is working for you, then maybe it is how I set up the catalog item? This is a mystery to me especially since many others commented that this functionality is working for them.
function getParameterValue(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
alert(name);
var regexS = "[\\?&]" + name + "=([^&#]*)";
alert(regexS);
var regex = new RegExp(regexS);
alert(regex);
var results = regex.exec(top.location);
alert(results);
if (results == null) {
return "";
} else {
return unescape(results[1]);
}
}

- 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.