Onload Catalog Client script top.windows.location infinity loop

Edxavier Robert
Mega Sage

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?

1 ACCEPTED SOLUTION

Edxavier Robert
Mega Sage

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. 

View solution in original post

17 REPLIES 17

Yes, but I'm getting an error message: 

EdxavierRobert_0-1705688906890.png

 

One more try

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.

Edxavier Robert
Mega Sage

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.