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

thanks a lot for your help

 

bmooney
Giga Contributor

You could use something like this too

function onLoad() {
//Parse top window url and set app_sys_id variable based on sys_id
var url = top.window.location.href;
var queryString = top.window.location.search;
var urlParams = new URLSearchParams(queryString);
var module = urlParams.get(NAME);
if (NAME) {
g_form.setValue('field', NAME);
}
}