The CreatorCon Call for Content is officially open! Get started here.

GlideURL not working in OnLoad catalog client script while trying to fetch one of the URL parameters

sharan16
Tera Contributor

GlideURL not working in esc portal -  OnLoad catalog client script while trying to fetch one of the URL parameters.

(There is a JavaScript error in your browser console)

 

Below is the OnLoad catalog client script

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

 

    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_id");
            return value;
        }
    }

 

Is there any alternative way to fetch url parameters?

7 REPLIES 7

Samaksh Wani
Giga Sage

Hello @sharan16 

 

Plz follow the below link ro solve your query :-

 

https://sncommander.com/how-to-get-parametersvalues-from-a-url-in-servicenow/

 

Plz mark my solution as Accept, If you find it helpful.

 

Regards,

Samaksh

Harsh_Deep
Giga Sage
Giga Sage

Hello @sharan16 

 

You can use below script-

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

Plz mark my solution as Accept, If you find it helpful .

Thanks

Still getting the same error.  I think the below code also need to be replaced.

if (!value) {
   var gUrl = new GlideURL();
    gUrl.setFromCurrent();
    value = gUrl.getParam("sysparm_id");
    return value;
        }

Jaspal Singh
Mega Patron
Mega Patron

Hi,

Try below.

var myparm = getParmVal('sysparm_universal_request');
if (myparm) {
        g_form.setValue('ur', myparm);
    }

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