Updating the "Update" record functionality, save and then redirect to previous page.

nikhilgupta2
ServiceNow Employee
ServiceNow Employee

I'm working on updating the "Update" button functionality. Upon making changes to a record (lets say a Business rule), we first check if the record belongs to a specific table. If it does, upon clicking "Update", we show a prompt to use that this is not a risky file, so don't update it. But if the user clicks "Proceed", we go ahead, save the record, and redirect the page to the previous one. 

 

Now, after updating the UI functionality and implementing the logic, I am able to perform save. Example:

 

function proceedWithUpdateFromForm() {
 g_form.save();

 if (dlg != null) {
 dlg.destroy();
 }
}

However, the moment I add the redirect logic, the redirect to previous page works fine, but Save doesn't work
function proceedWithUpdateFromForm() {
g_form.save();

if (dlg != null) {
dlg.destroy();
}

if (returnUrl != 'null') {
window.location.href = window.location.protocol + '//' + window.location.host + '/' + returnURL;
} else {
window.location.href = window.location.protocol + '//' + window.location.host + '/' + tblName + '_list.do?sysparm_userpref_module=' + module + '&sysparm_query=' + listQuery + '&sysparm_cancelable=true';
}
}

 

I'm attaching the sys_ui_action file, script_include and sys_ui_page relevant for the code. 

 

Kindly advice. 

1 ACCEPTED SOLUTION

nikhilgupta2
ServiceNow Employee
ServiceNow Employee

Using g_form.submit and most importantly, creating a new sys_ui_action with table name="sys_metadata" and doing n an "override" onto the main sys_ui_action for Update worked. 

View solution in original post

5 REPLIES 5

Abhijeet_Pawar
Tera Guru

Hello @nikhilgupta2 ,

use action.setReturnURL(current); method in your script.

I hope this will resolve your issue.

Hi @Abhijeet_Pawar 

Since sys_ui_action is a client side script (as I enabled "client"), "current" is not valid there, as "current" is used in server-side scripts. Please correct me if I'm wrong. And that why the following code lines, including action.setReturnURL(current) won't get executed. 

current.update();
var url = new sn_sow_inc.SOWIncidentUtils().getNewIncidentTaskLink(current);
action.setRedirectURL(url);
action.setReturnURL(current);

 Please advice. 

nikhilgupta2
ServiceNow Employee
ServiceNow Employee

Any suggestions?

nikhilgupta2
ServiceNow Employee
ServiceNow Employee

Using g_form.submit and most importantly, creating a new sys_ui_action with table name="sys_metadata" and doing n an "override" onto the main sys_ui_action for Update worked.