gs.setRedirect is not working in portal widget server side script

Amit Kumar21
Tera Contributor

I am unable redirect to any URL using setRedirect in server side script of the widget i am working on. Can someone help on how can we do that or where is the issue.

Added the code snippets.

1 ACCEPTED SOLUTION

Ahmmed Ali
Mega Sage

Hello @Amit Kumar21 

 

Let me know if my understanding is wrong. In portal, in request item status page, you want to show a button/link on clicking of that button/link, user should be redirected to the catalog item page.

If yes, current solution is not good as it is making additional server call. updated solution below:

 

1. in server script, I can see you have the requestGr object which I am assuimg the GlideRecord object of the RITM record. You can save the sys_id of the catalog item in data object in server script as below:

data.cat_item_link = "?id=sc_cat_item&sys_id" + requestGr.getValue("cat_item");

 

2. in html, remove onclick attribute and update href as href='{{c.data.cat_item_link}}' 

 

Thanks,

Ali

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

View solution in original post

5 REPLIES 5

Sagar Pagar
Tera Patron

Hi @Amit Kumar21,

 

Try with window.open() to open the URL in new tab or same tab.

 

Same tab:

window.open(baseURL, '_self');

 

New Tab:

window.open(baseURL, '_blank');

 

 

Thanks,

Sagar Pagar

The world works with ServiceNow

Ahmmed Ali
Mega Sage

Hello @Amit Kumar21 

 

Let me know if my understanding is wrong. In portal, in request item status page, you want to show a button/link on clicking of that button/link, user should be redirected to the catalog item page.

If yes, current solution is not good as it is making additional server call. updated solution below:

 

1. in server script, I can see you have the requestGr object which I am assuimg the GlideRecord object of the RITM record. You can save the sys_id of the catalog item in data object in server script as below:

data.cat_item_link = "?id=sc_cat_item&sys_id" + requestGr.getValue("cat_item");

 

2. in html, remove onclick attribute and update href as href='{{c.data.cat_item_link}}' 

 

Thanks,

Ali

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Amit Kumar21
Tera Contributor

Hi,

Thanks for the reply, But i was unable to redirect to catalog item after the changes suggested by you. i am attaching the code snippets.

Hi,

 

In server script, input will not work in your code lines as you are not calling the server script from client side. Remove if condition. just get the RITM GlideRecord and get the catalog item sys_id from the GlideRecord and set in url.

 

Thanks,

Ali

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali