- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2022 01:52 AM
Hi Everyone,
How i should get order guides sysid in on load catalog client script.
I tried the below code it is working for me in portal but not on native view.
in native view i tried g_form.getParameter("sysparm_id") as well even this is not working i am getting a null value.
var url = top.location.href;
var orderGuideSysId;
if(window == null){
// for portal
orderGuideSysId = new URLSearchParams(url).get("sys_id");
}
else{
// for native
orderGuideSysId = new URLSearchParams(url).get("sysparm_guide");
}
alert(orderGuideSysId);
}
I am getting the alert of null in native view load and in portal its working fine.
Regards,
Debasis
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2022 02:40 AM
Hi
update as this
Ensure Isolate Script field is False for your client script for allowing DOM i.e. window
function onLoad(){
var url = top.location.href;
var orderGuideSysId;
if(window == null){
// for portal
orderGuideSysId = new URLSearchParams(url).get("sys_id");
}
else{
// for native
var gUrl = new GlideURL();
gUrl.setFromCurrent();
orderGuideSysId = gUrl.getParam("sysparm_guide");
}
alert(orderGuideSysId);
}
OR use this and Keep Isolate Script = True
function onLoad(){
try{
var url = top.location.href;
var orderGuideSysId;
if(window == null){
// for portal
orderGuideSysId = new URLSearchParams(url).get("sys_id");
}
}
catch(ex){
// for native
var gUrl = new GlideURL();
gUrl.setFromCurrent();
orderGuideSysId = gUrl.getParam("sysparm_guide");
}
alert(orderGuideSysId);
}
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-14-2022 02:18 AM
Uncheck the isolate script, then it will work in Native UI as well. See the below image for reference.
If that field is not available on the form, then you have to bring it on the form via form layout.
Check out this article, it will help you understand the behavior of top, window and doument objects.
Top Window Document Objects in Native UI and Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2022 02:40 AM
Hi
update as this
Ensure Isolate Script field is False for your client script for allowing DOM i.e. window
function onLoad(){
var url = top.location.href;
var orderGuideSysId;
if(window == null){
// for portal
orderGuideSysId = new URLSearchParams(url).get("sys_id");
}
else{
// for native
var gUrl = new GlideURL();
gUrl.setFromCurrent();
orderGuideSysId = gUrl.getParam("sysparm_guide");
}
alert(orderGuideSysId);
}
OR use this and Keep Isolate Script = True
function onLoad(){
try{
var url = top.location.href;
var orderGuideSysId;
if(window == null){
// for portal
orderGuideSysId = new URLSearchParams(url).get("sys_id");
}
}
catch(ex){
// for native
var gUrl = new GlideURL();
gUrl.setFromCurrent();
orderGuideSysId = gUrl.getParam("sysparm_guide");
}
alert(orderGuideSysId);
}
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-14-2022 03:56 AM
in native view the above script gives undefined as alert
