Decode URI is not working as expected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2022 09:56 AM
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;
}
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2022 05:06 PM
you probably want decodeURIComponent
instead. What was the original URL?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2022 05:37 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2022 06:34 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2022 02:01 PM
Hello
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;
}
}