Both decodeURIComponent() and decodeURI() not work on scoped application
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2020 04:37 AM
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]);
}
- Labels:
-
Personal Developer Instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2020 04:51 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2020 05:05 AM
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2020 05:14 AM
Hi,
which parameter value you want to retrieve?
Also on which table this script is running?
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
03-24-2020 05:24 AM
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;
}