- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2024 03:20 PM
Hi all,
I am currently working on a catalog client script to re-direct user to a specific page after they click on a catalog item. I was able to do it by using an Onload catalog client script but after it re-directs gets into an infinity loops.
function onLoad() {
//Type appropriate comment here, and begin script below
top.window.location = "sp?id=sc_cat_item_new_page&sys_id=109cdff8c6112276003b17991a09ad65";
}
How I can prevent the infinity loop?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 10:41 AM - edited 01-19-2024 10:42 AM
Here is how I got it worked.
1. Create a new service portal page, added my custom widget
2. Duplicate the catalog item
3. Hide the original catalog item from the portal
4. On the new catalog item added the catalog client script pointing to the original catalog item on the new page.
Tested out and working fine, when the user click on the new catalog item it re-direct very quick to the correct one. User will see like a flash less than a second the new one but is very fast. I didn't added any variables to the new one as it always will re-direct the user to the correct catalog item.
An additional thing that I had to do on the new page was to add new Dynamic page title variable to get the catalog item name on the title tab.
Thanks @SanjivMeher and @Jim Coyne for all your suggestions.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 08:12 AM
Ok. Below script should work. If not, try adding some alert message to debug
function onLoad() {
//Type appropriate comment here, and begin script below
var oldloc = top.window.location;
if (oldloc.indexOf('sp?id=sc_cat_item_new_page')==-1)
top.window.location = "sp?id=sc_cat_item_new_page&sys_id=109cdff8c6112276003b17991a09ad65";
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2024 11:15 PM
How is your solution configured? What happens if you go directly to your new page? Does it loop that way as well? I see you tried my Catalog Client Script example from this question: Is there a way to redirect the catalog item to category page in ESC portal ?
I setup an example scenario in my PDI like this:
1. A Catalog Item that needs to be "retired" or re-directed from:
2. I created a Variable Set that only includes a new "onLoad" Catalog Client Script. That script is configured to re-direct to a Content Item that presents a list of options to users. The UI Type is set to "All" and the script is:
function onLoad() {
//re-direct to the "Test - Redirect Old Item to Content Item" Content Item
top.window.location = "?id=sc_cat_item&sys_id=329c9dc69333311005db7b732bba105e";
}
Tip: NOT specifying the "sp" at the beginning of the URL will ensure the user will go to the page I want but remain in the same portal they are already in. You may or may not want that.
3. With the Variable Set added to the old Catalog Item, when a user now goes to it, they will be automatically re-directed to the Content Item I've created with the sys_id in the URL above:
The reason I created the Catalog Client Script within a Variable Set is because you might end up having a number of old Catalog Items you want to re-direct your user from. This way you can just add the Variable Set to those items.
And obviously the URL in the Catalog Client Script can point to anywhere. I created the Content Item as an example solution for the other question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 06:35 AM - edited 01-19-2024 06:37 AM
Hi Jim,
Thanks for your response.
Here is my use case, I have this catalog item lets called Example Catalog which I wanted to re-direct to a different page than the sc_cat_item page. So what I did it I went to pages duplicated the sc_cat_item page to create another page sc_cat_item_new_page. I was trying to use the same logic that you use on your post .
But for some reason it gets into an infinite loops. If I go directly into the new page it will stay in the page, no issues.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 06:46 AM - edited 01-19-2024 06:47 AM
Did you add the Catalog Client Script to the "Example Catalog" item and then use the "Copy" button to make the new item? Is there an onLoad Catalog Client Script attached to that new item? The "Copy" button would make a copy of the initial item with all the variables, client scripts, UI Policies, etc...
Do you have the sys_id of the new item in the Catalog Client Script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 06:51 AM
I think making this script run on onLoad is not correct, it will always go on infinity loops.
Just a ask what you are trying to open in new page?
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.
********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect
Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************