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

Hi Ripu,

I used the mentioned onChange script but without success

Requirements:

If variable (what_would_you_like_to_do) selection changes to 'Create New Catalog Item' then redirect to https://mhsdev.service-now.com/sp?id=sc_cat_item&sys_id=70651f5c1b55141027a8620bbc4bcb92

=====Here is the onChange script I am using=====

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

//Type appropriate comment here, and begin script below
if (newValue == 'Create New Catalog Item'){
var redirectURL = 'https://mhsdev.service-now.com/sp?id=sc_cat_item&sys_id=70651f5c1b55141027a8620bbc4bcb92';
top.window.location = redirectURL ;
}
}

 

see attachment for screenshot

 

shiven
Tera Contributor

I Guess the above does not work for on summit client script in catalog item ?

That too in scoped app.

Hi Shiven

I have tried this recently in on-submit client script. The solution provided by Ripu should work. If this is not working, then try with below.

 

var url = "YOUR URL"

top.window.onbeforeunload = null;
top.window.onunload = null;
top.window.location = url;