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.

Unable to get the parameter value from URL

Rakesh50
Mega Sage

We are trying to get the value from URL by using onload catalog client script but we couldn't.

URL : https://test.service-now.com/nav_to.do?uri=%2Fu_cx_catalog_picker.do%3Fsysparm_parent_anchor%3Dhttps:%2F%2Ftest.service-now.com%2Finteraction.do%253Fsysparm_record_list%253DORDERBYDESCnumber%2526sysparm_record_rows%253D29%2526sysparm_record_row%253D8%2526sysparm_record_target%253Dinteraction%2526sys_id%253D0ae8bcc71bafc1d8c8e7db9ebd4bcb06%26sysparm_parent_number%3DIMS0000028%26sysparm_parent_sys_id%3D0ae8bcc71bafc1d8c8e7db9ebd4bcb06%26sysparm_parent_table%3Dinteraction

From above URL we need sysparm_parent_sys_id parameter value. We tried below script please check and let us know if any corrections 

function onLoad() {
//Type appropriate comment here, and begin script below
var InteractionSysID = getParameterValue('sysparm_parent_sys_id');

alert(InteractionSysID);
if(InteractionSysID !='')
g_form.setValue('interaction',InteractionSysID);
function getParameterValue(name) {
var url = top.location.href;
var value = new URLSearchParams(url).get(name);
if (value) {
return value;
}
}
}

In alert we are getting null value

7 REPLIES 7

Chetan Mahajan
Mega Sage

Hi,

            try this

function getParameterValue(name) {
        var url = top.location.href;
        var value = new URLSearchParams(url).get(name);
        if (value) {
            return value;
        }
        if (!value) {
            var gUrl = new GlideURL();
            gUrl.setFromCurrent();
            value = gUrl.getParam("sysparm_parent_sys_id");
            return value;
        }
    }

RAHUL YADAV9
Mega Guru

This article may help you.

https://servicenowguru.com/scripting/client-scripts-scripting/parse-url-parameters-client-script/

Feel free to mark correct and helpful.

we tried but not worked

Chetan Mahajan
Mega Sage

Hi,

     Try This 

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