how to redirect user to a different page and close it automatically using a server side script

Alon Grod
Tera Expert

how to redirect user to a different page and close it automatically using a server side script inside a UI Action:

how can i adjust this script so that it wil redirect to the new window but it will be closed automatically

 if (result.status === 'success' && result.attachment_id) {
        var downloadURL = '/sys_attachment.do?sys_id=' + result.attachment_id;
        action.setRedirectURL(downloadURL);
}

 

2 REPLIES 2

Chaitanya ILCR
Giga Patron

Hi @Alon Grod ,

it's not possible open a new window from server side script.

you can make this UI Action to run on client side and use the g_navigation or window.open to open the new window 

 

https://developer.servicenow.com/dev.do#!/reference/api/zurich/client/c_GlideNavigationV3API#r_GNV3-...

 

and move the logic to the client callable script include and use GlideAjax in the UI action to perform the action

 

there is a method setReturnURL(to set the return url after the follow up action is taken on the redirected url) in the server side but it won't work in this scenario

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

Tanushree Maiti
Kilo Sage

If this UI action is at client side, you can try

window.open(url, '_blank');


If this is server side, you can try:

action.setRedirecturl() method.

TanushreeMaiti_0-1770536669522.png

 

Please mark this response as Helpful & accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: