- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hello all
I have a requiremnet as follows:
previously, we had 3 cat items, and now we have combined them into single order guide
The issue is, some users still have sepearate link of individual cat items
our requirement is if they access the cat item individually, they should be redirected to correct newly created order guide
to achieve this, we have created a on load client script which works well for ESC portal(using g_service_catalog.isOrderGuide())
however, there are still some users who use service catalog
to handle ESC redirection , we have following code in onLoad script which is applied to cat item
function onLoad() {
//we are checking if url contains esc to check if it is being accessed from esc or self service
if (top.location.href.indexOf("esc") > -1) {
var orderguideornot = g_service_catalog.isOrderGuide();
if (orderguideornot === false) {
//here we are redirecting to correct order guide using top.window.location
}
} else {
//now we know its from self service, we want to have the method which can tell us it does not belongs to order guide, so redirect it
}
}
I even tried to use the getParameter method as below, but the results are always null
function getUrlParameter(name) {
var url = top.location.href;
var params = new URLSearchParams(url).get(name);
return params;
}
//here my checking of ESC as like prev code works
else{
var sysId = getUrlParameter('sysparm_guide');
alert(sysId);
}
if anyone has worked on similar kind of requirment, let me know how can I solution this
Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago - last edited 2 weeks ago
Unfortunately, I tried many ways such as URLSearchParams, GlideURL etc
I dont know what was the root cause for this, but finally I used normal comparison as follows:
function onLoad() {
if (top.location.href.indexOf("esc") > -1) {
var orderguideornot = g_service_catalog.isOrderGuide();
if (orderguideornot === false) {
//I used the correct redirect link here using top.window.location
}
} else {
var currentUrl = top.location.href;
if (!currentUrl.includes("sysparm_guide=")) {
//I used the correct link here using top.window.location
}
}
}
This worked for me
Thank you!
Gaurav Vaze
Servicenow Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hi @Gaurav Vaze
May you try this code
function onLoad() {
// If in ESC
if (top.location.href.indexOf("esc") > -1) {
if (!g_service_catalog.isOrderGuide()) {
redirectToGuide();
}
}
// If in Service Portal / Self Service
else {
var guideSysId = new URLSearchParams(window.location.search).get("sysparm_guide");
if (!guideSysId) {
redirectToGuide();
}
}
}
function redirectToGuide() {
// Replace with your new Order Guide sys_id
top.location.href = "/esc?id=order_guide&sys_id=PUT_GUIDE_SYSID_HERE";
}
This will:
- Redirect users who open the old item directly (ESC or Service Portal).
- Do nothing if the item is already opened inside the new order guide.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
unfortunately, it does not contains any value
i used alert to debug what value is stored in guideSysId, but it did not poped up eveb
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago - last edited 2 weeks ago
Unfortunately, I tried many ways such as URLSearchParams, GlideURL etc
I dont know what was the root cause for this, but finally I used normal comparison as follows:
function onLoad() {
if (top.location.href.indexOf("esc") > -1) {
var orderguideornot = g_service_catalog.isOrderGuide();
if (orderguideornot === false) {
//I used the correct redirect link here using top.window.location
}
} else {
var currentUrl = top.location.href;
if (!currentUrl.includes("sysparm_guide=")) {
//I used the correct link here using top.window.location
}
}
}
This worked for me
Thank you!
Gaurav Vaze
Servicenow Developer