Using Onload script i need to change the URL of the instance if the catalog item stored in bookmarks
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2024 07:25 AM
below is the Onload script i written but not working
function onLoad() {
// Ensure `window` is available and check the current URL
if (typeof window !== 'undefined') {
var url = window.location.href;
// Check if the current page is a catalog page (adjust the identifier as needed)
if (url.includes('sc_cat_item')) {
// Define the new URL to redirect to
var newUrl = url.replace(/https:\/\/[^/]+\/sc_cat_item/, 'https://dev228177.service-now.com/your_new_catalog_page');
// Optional: Modify query parameters if needed
var urlObj = new URL(url);
var sysId = urlObj.searchParams.get('sys_id');
if (sysId) {
newUrl += (newUrl.includes('?') ? '&' : '?') + 'sys_id=' + sysId;
}
// Redirect to the new URL
window.location.assign(newUrl);
}
}
}
0 REPLIES 0