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

Nopes, does not work for internal url as well.



getTopWindow().NavPageManager.get().getPane('gsft_main').loadLinkFromUrl("https://dev10405.service-now.com/incident.do?sys_id=-1&sysparm_query=active=true&sysparm_stack=incid...");



Window.location is working fine.



Regards
Pratul Agarwal


Remove the instance part, we expect it to be internal anyway



getTopWindow().NavPageManager.get().getPane('gsft_main').loadLinkFromUrl("/incident.do?sys_id=-1&sysparm_query=active=true&sysparm_stack=incident_list.do?sysparm_query=active...");




This way it is also portable between instances using our update sets without the need for change.


Has this changed with Helsinki/U16? Getting complaints about .get(): Cannot read property 'get' of undefined


Are you working in a scoped app?


I'm in Global, and it seems that both NavPageManager and g_navManager doesn't work anymore.