Client Script: redirect onLoad

tahnalos
Kilo Sage

Hello

We are trying to implement functionality which is supposed to ask for additional information before a Change is worked on.

The intent is that if the assignee is supposed to start work on the change, there may be some additional information that may need to be entered before the change can be worked on.

The idea is to have a redirect from the Change form to this separate form to log details, and once the details are all entered, it is supposed to redirect back to the Change Request form.   This form is supposed to be linked to the Change record as well.

I've seen action.setRedirect being used but that's more on the server side, and wondering if there is a client side redirect I can use?

Thanks.

1 ACCEPTED SOLUTION

Sorry, should be



g_navigation.openPopup( 'change_request.do?sys_id=-1&sysparm_query=parent=' + g_form.getValue('sys_id'), 'New Change');



New Change is the title of the Popup


The sys_id=-1 part opens a new change request


The parent= + g_form.getValue('sys_id') will auto populate the 'parent' field, so you can relate it back to the origin change.



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

View solution in original post

10 REPLIES 10

The SN Nerd
Giga Sage
Giga Sage

Please see the g_navigation API.



https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=c_GlideNavigationV3API



You should avoid using the DOM (ie top.window.redirect) when ServiceNow provides the API to do it for you.



Example:



g_navigation.openRecord('change_request',sys_id_here);



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Thanks Paul.   OpenRecord would help with the case where I am trying to redirect back to the change, but wondering about a redirect directly to a new record that would be the child of a change.



Thanks


Instead of redirecting from the new record, you might consider using the openPopup API.



For example, if you are using the Parent field for you relationship, this opens a new Change Request which will be related to the originating Change:



g_navigation.openPopup( 'change_request.do?sys_id=-1&sysparm_query=parent=' + g_form.getValue('sys_id) + 'New Change');



This eliminates the need to redirect back to the parent.




ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022