Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to get URL param values in record producer for Service portal?

Sebaslag
Giga Expert

Hello
I would like to add values in my form using url but it doesn't work. I made a client script:

function onLoad()
{
var serviceinput = getParameterValue('sysparm_service');
if (varserviceinput)
{
g_form.setValue('category', 'service');
g_form.setValue('business_service', serviceinput);
}
}

function getParameterValue(name)
{
var url = document.URL.parseQuery();
if (url[name])
{
return decodeURI(url[name]);
} else
{
return;
}
}

 

But as soon as I open my catalog item I have a JavaScript error.find_real_file.png

What am I doing that is not working? And how to call my url?

thank you very much

1 ACCEPTED SOLUTION

You can use the script below as mentioned in the following post:
https://community.servicenow.com/community?id=community_blog&sys_id=ec3eea6ddbd0dbc01dcaf3231f9619d6

 

URL with parameter: 

https://<instance name>.service-now.com/nav_to.do?uri=com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=d65394f54ff2520020af09fd0210c759&sysparm_user=2809952237b1300054b6a3549dbe5dd4

 

function onLoad() {
    //Type appropriate comment here, and begin script below
    var user = getParameterValue('sysparm_user');
    if (user) {
        g_form.setValue('descriptionTest', user);
    }
}


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

}

View solution in original post

6 REPLIES 6

Robrecht1
Tera Expert

What error do you receive when you check the browser console log? What is it telling you?

find_real_file.png

seems to be the function document.url.parse query() that is not working.

You can use the script below as mentioned in the following post:
https://community.servicenow.com/community?id=community_blog&sys_id=ec3eea6ddbd0dbc01dcaf3231f9619d6

 

URL with parameter: 

https://<instance name>.service-now.com/nav_to.do?uri=com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=d65394f54ff2520020af09fd0210c759&sysparm_user=2809952237b1300054b6a3549dbe5dd4

 

function onLoad() {
    //Type appropriate comment here, and begin script below
    var user = getParameterValue('sysparm_user');
    if (user) {
        g_form.setValue('descriptionTest', user);
    }
}


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

}

ok i no longer have the javascript error but when i enter the url it redirects me not to the portal service but to the portal agent. How to go to the SP?

 

https://servicenow.domain/nav_to.do?uri=com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=b545558c1b47a0104426524f034bcbfc&sysparm_service=7279a98f1b16a8100e87caee034bcbbb