Close Code and Close notes mandatory for Change Request in 'Canceled' state

anubhavr
Giga Expert

As 'Cancel Change' is a UI Actions and it is not Client so we cannot use g_form.setMandatory function in UI Action. I tried to do it using Script include with 'Client Callable' but still I guess I can't use Glide Form functions in Script Include. I Tried with UI Policies also but not working. Can anyone suggest me solution for this??

11 REPLIES 11

marcguy
ServiceNow Employee
ServiceNow Employee

you will need to update the Cancel Change UI Action to run in the client first, here is one I use for ensuring work_notes are entered when cancelling, you can change this to display close code and notes and make them mandatory:




Client: True


onClick: cancelChange()




function cancelChange(){


  var wn = g_form.getValue('work_notes');


  if (wn == ''){


  g_tabs2Sections.setActive(3);


  g_form.flash('work_notes','red',1);


  g_form.clearMessages('work_notes');


  g_form.showFieldMsg('work_notes','Work Notes are Mandatory when Cancelling a Change','error');


  g_form.setMandatory('work_notes', true);


  return false;


  }


  gsftSubmit(null, g_form.getFormElement(), 'cancel_change'); //MUST call the 'Action name' set in this UI Action



}


  //Ensure call to server-side function with no browser errors


  if (typeof window == 'undefined')


  moveToCancel();





function moveToCancel(){


  action.setRedirectURL(current);



  if (new ChangeRequestStateHandler(current).moveTo("canceled"))


  current.update();


}


Hi,


I tried it but when I try to open any change request, It is going back to list after loading the form page. I guess i we make the UI policy to run in Client side, We cannot use 'current' keyword as it is used in server side only.


Hi,



Thank you. Its working now. I made mistake in placing Close bracket earlier.


Anubhav,



I am having the same issue that you addressed above. I modified the script above to make this functional for Closed Notes and Close Code to be mandatory upon cancelling the change request. This works great. However, once I complete the fields and then select cancel again, it brings me back to the list view of All the change requests and the one I canceled in particular does not go into a Canceled stated. Any Ideas? Here's the code I'm using:



find_real_file.png