Both decodeURIComponent() and decodeURI() not work on scoped application

Antonio42
Kilo Guru

Team, I am trying to decode an URL, but I am getting undefined value. Could you guys know how to resolve it?
Find below my code:

function getParameterValue(pName){

    var glideURL = new GlideURL();
    glideURL.setFromCurrent();
    var url = glideURL.getParam(pName);

    return decodeURI(url[pName]);
    //return decodeURIComponent(url[pName]);
}

 

15 REPLIES 15

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

basically you want to get url parameter value; use this in scoped app; it should work in scoped app and portal as well

var url = top.location.href;
var param = new URLSearchParams(url).get("my_param");

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur, thanks for your reply!

It is taking me an incomplete URL, check the URL output: uri=%2Fnew_call.do%3Fsys_id%3D-1%26sysparm_stack%3Dnew_call_list.do.

Check my code:


alert(top.location.href);

function getParameterValue(pName){

    var url = top.location.href;
    var param = new URLSearchParams(url).get(pName);    
 
    return param;

}

Hi,

which parameter value you want to retrieve?

Also on which table this script is running?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi,

This is an onload catalog client script. I am trying to retrieve values from New Call module, here is my whole script:

function onLoad() {
    var vUser = getParameterValue('sysparm_caller')+'';
    var vEmail = getParameterValue('sysparm_caller_email')+'';
    var vPhone = getParameterValue('sysparm_caller_phone')+'';
   
    if (vUser != '') {
        g_form.setValue('variables.caller_id', vUser);
        g_form.setValue('variables.email', vEmail);
        g_form.setValue('variables.phone', vPhone);
    }
}

//alert(top.location.href);

function getParameterValue(pName){

    var url = top.location.href;
    var param = new URLSearchParams(url).get(pName);    

    return param;
}