Decode URI is not working as expected

deepum
Giga Guru

Hello All,

I am trying to decode a URL, but due to the special character "&", the url is not being coming back as expected. 

url that has to comeback: com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=342dc43a60d929007c9ff3c5c6f68fcf&sysparm_filter=assignment_group=da73fd09db2963001fafd0c0ce961951^state=1^assigned_to=d8d103f4c8722500ceb1e6aedf04ae98^last_found<javascript:gs.dateGenerate('2022-08-04','start')&sysparm_vulid=&sysparm_filtertype=defined

 

In the above link, in the sys_param_filter because of the highlighted portion, the url is not taking the entire filter, which results in the issue of list of the records. How to deal with this issue. used below code. 

Please help me on this. Thanks

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

4 REPLIES 4

Luke Van Epen
Tera Guru

you probably want decodeURIComponent instead. What was the original URL?

this is the original url : var url = 'com.glideapp.servicecatalog_cat_item_view.do?sysparm_id='+recordProducerID + '&sysparm_filter=' + queryF + '&sysparm_vulid=' + vulnString + '&sysparm_filtertype='+ allFilter;

I am rendering this from a UI page

 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use this to get url parameter value

can you try this and check once

var url = top.location.href;
var val = new URLSearchParams(url).get("sysparm_Comp");
alert(val);

Regards
Ankur

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

Hello @Ankur Bawiskar , Please help me on this.

I have used your inputs but did not work as expected. I might written the script wrong.

Below is my code. the filter value is not working as expected when ever we use greater or less than in the filter.

function onLoad() {
    //Populate the variables with the parameters passed in the URL
    //Use the 'getParmVal' function below to get the parameter values from the URL
    var filterV = getParmVal('sysparm_filter');
    var filterTypeV = getParmVal('sysparm_filtertype');
    var vulV = getParmVal('sysparm_vulid');
    
    if(filterV){
        g_form.setValue('u_vulnerability_filter',filterV);
    }
    if(vulV){
        g_form.setValue('u_vulnerable_ids',vulV);
    }
    if(filterTypeV){
        g_form.setValue('u_filter_type',filterTypeV);
    }
}

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