Can we redirect using client script

HarshTimes
Tera Guru

Can we redirect to any other page or homepage using client script.
I need that if the IF condition true then redirect to homepage.Please help me out

1 ACCEPTED SOLUTION

Ripu Daman1
Tera Expert

I know this post is old and Harsh might have got his answer but just in case someone stumbles upon this post and looking for a way to redirect using client script then below code snippet might help:

 

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

//Type appropriate comment here, and begin script below
if (newValue == 'expense_freight_realestate'){
var redirectURL = 'https://www.google.com/'; //url to redirect; this approach works in platform and Service Portal view
top.window.location = redirectURL ;
}
}

 

Please note that in case you want to open up external link within the main ServiceNow Frame then you may use g_navigation.open() but this approach doesnt work when the Service Catalog/form will be used in Service Portal.

View solution in original post

17 REPLIES 17

Mark Stanger
Giga Sage

Just set window.location to redirect from client-side script.

https://developer.mozilla.org/en-US/docs/DOM/window.location


The ServiceNow way to do it would be:


getTopWindow().NavPageManager.get().getPane('gsft_main').loadLinkFromUrl( <url> );



This makes it look seemless to the user.


Hi Fogg,



This is not working for me, the client side code is triggered but it does not takes me to the url.



getTopWindow().NavPageManager.get().getPane('gsft_main').loadLinkFromUrl("http://www.google.com");



This is the code I am using.



Regards


Pratul Agarwal


I believe this only works for internal URLs to the ServiceNow instance.


For external ones you will need to do something like window.location = "http://www.google.com";