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
‎07-17-2022 09:53 PM
Hi
on client side there is a OOTB object g_uri you can use.
In the following page all methods are listet: https://community.servicenow.com/community?id=community_question&sys_id=d960d729dbdcdbc01dcaf3231f96...
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2022 10:49 PM
Hello Maik,
Will this work client side ?
I tried this..
var uri = g_uri.action();
var fileString = uri.get('sysparm_product_sysid');
g_form.addInfoMessage('fileString '+fileString);
Error:
ReferenceError: g_uri is not defined
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 04:47 PM
Hi, try using top.location.href
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2024 08:18 AM
This Works!