- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2020 01:27 AM
Hi,
I've been using the following script (below) for years to pass URL parameters and just found out that it does not work in Service Portal. I've seen a few possible workarounds but none of them worked.
Anyone have a good solution to getting this to work in Service Portal? i would normally use the below in an onLoad script.
Closest thing i found to a workable fix is: https://jace.pro/post/2018-07-15-sp-set-variables-via-url/ but not 100% clear how to implement it.
var appointment = getParameterValue('sysparm_appointment');
function getParameterValue(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location);
if (results == null) {
return "";
} else {
return unescape(results[1]);
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2020 02:01 AM
Hi,
that's because window object is not recommended by ServiceNow; instead use this and check
var url = top.location.href;
var appointment = new URLSearchParams(url).get("sysparm_appointment");
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-26-2020 02:01 AM
Hi,
that's because window object is not recommended by ServiceNow; instead use this and check
var url = top.location.href;
var appointment = new URLSearchParams(url).get("sysparm_appointment");
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-26-2020 02:17 AM
Many thanks 🙂
I was able to get away with replacing window.location with top.location.href
Much appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 03:09 AM
Excellent solution, thanks for sharing.
Kind Regards
Ashley