Get URL value in client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2022 09:47 PM
Hi,
I am trying to load portal page from a ui page. This page is a record producer.
I am able to to that (loading portal page).
Suppose my url that coming on portal is :https://<INSTANCE>.service-now.com/portal?id=sp_home&sysparm_product_sysid=<product sys id>
I want to give a check if sysparm_product_sysid
has some value then the a field on item should be auto checked as true on load.
For this i have added a onload client script in my record producer.
My ui type is set to Mobile/Service portal on client script .
and I have enabled isolate script to true.
Tried both ways but none of them is working. When the portal is loaded, its giving error..
1.
var prdID = getParmVal('sysparm_product_sysid');
if(prdID){
alert('prd');
//g_form.addInfoMessage('prd');
}
}
function getParmVal(name){
var url = document.URL.parseQuery();
if(url[name]){
alert('inside function');
return decodeURI(url[name]);
}
else{
return;
}
Error:
2.
var gUrl = new GlideURL();
gUrl.setFromCurrent();
var prdID= gUrl.getParam("sysparm_product_sysid");
alert('prdID '+prdID);
Error message:
Reference pages:
https://servicenowguru.com/scripting/client-scripts-scripting/parse-url-parameters-client-script/
https://community.servicenow.com/community?id=community_question&sys_id=955ffdb3db1e6340656a5583ca96...
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2024 10:50 PM
Worked like a charm! Thank you 😊
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2024 03:07 AM
It worked, I appreciate it

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2025 05:10 AM
Hi, you can use the property top.location.href in combination with the JavaScript object URLSearchParams. This makes it very flexible and easy to use.
Here is an example script:
var url = top.location.href;
var params = new URLSearchParams(url);
var parentSysId = params.get('sysparm_collectionID');
if (parentSysId) {
g_form.setValue('task', parentSysId);
}