How to redirect to another form on onChange of field.

Aakash007
Tera Contributor

How to open a new form in new tab on change of field value of a form.

1 ACCEPTED SOLUTION

@Aakash007 

g_navigation won't work in portal.

you need to use top.window

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


	if (newValue == 'some value'){
		var redirectURL = 'https://something.service-now.com/itsp?id=sc_catalog_item&sys_id=something'; 
		top.window.open(redirectURL, "_blank");
	}
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

6 REPLIES 6

SatyakiBose
Mega Sage

Hello @Aakash007 

 

You can refer to the client script below:

 

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

//Type appropriate comment here, and begin script below
if (newValue == 'NEW_FIELD_VALUE'){
var redirectURL = 'https://www.google.com/'; 
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.

 

You can also refer to this community post here - https://www.servicenow.com/community/itsm-forum/can-we-redirect-using-client-script/m-p/385003

 

Aakash007
Tera Contributor

Hi Satyakibose
1. I need to redirect form on Service portal.
2. I am getting "g_navigation is not difined" on console

Thank you

SatyakiBose
Mega Sage

Hello @Aakash007 

Client scripts work differently when compared to native UI & service portal in terms of redirection.

Please check the KB article here: Redirect does not work in Service Portal - Support and Troubleshooting (servicenow.com)

Ankur Bawiskar
Tera Patron
Tera Patron

@Aakash007 

since you are in portal top.location will work fine

can you share what script you used and what's not working?

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader