We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Prepopulate fields on a service catalog item using a URL

Colleen1
Tera Contributor

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]);
       }
}

find_real_file.png

 

1 ACCEPTED SOLUTION

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.

View solution in original post

15 REPLIES 15

George Snyder
Tera Contributor

In case anyone else comes here looking, I wanted to share another link I found which provides an out of the box way to do this: Prefilling variable values on the catalog item form in the portal and Next Experience UIs • Australi...