g_form.checkMandatory = false; is not working accross multiple tabs of a change record

David Trotta
Tera Contributor

Hi everyone,

 

I am trying to bypass mandatory fields on a change record when the "Cancel Change Request" UI action is kicked off.

 

Currently, when someone clicks on Cancel Change Request (our UI action) it forces the user to complete all mandatory fields on the form before allowing them to cancel the change request.

 

Our change records have multiple tabs - a Planning tab with details of change, and Schedule tab with start and end dates of change window.  Both tabs contain mandatory fields.

 

Here is my issue.  The below script command works great on the main Planning tab and removes mandatory requirements for all the fields on that tab, but it doesn't apply to the Schedule tab.  I still have to populate the Start and End date fields on the Schedule tab before it will allow me to cancel the change

g_form.checkMandatory = false;
 
How do I configure the script to perform the function on ALL tabs within the change record?  I've even tried specifically calling out the Start and End date fields in the UI action (see below), but that doesn't work either.
 
function cancel(){  
  if(confirm("Are you sure you want to cancel this change?")){  
    //Cancel mandatory requirement on fields
    g_form.checkMandatory = false;
    g_form.setMandatory('start_date','false');
    g_form.setMandatory('end_date','false');
  //Call the UI Action and skip the 'onclick' function  
  gsftSubmit(null, g_form.getFormElement(), 'cancel_change_request'); //MUST call the 'Action name' set in this UI Action  
  return true;  //Abort submission  
  }  
  return false;  
 

Thanks in advance for any guidance on how to handle

 

Dave

7 REPLIES 7

Hi @David Trotta 

 

Can you use setWorkflow(false)?

 

Regards,

Amit

AshishKM
Kilo Patron
Kilo Patron

Hi @David Trotta,

There is OOTB Cancel Change UI Action on change_request table, are you setting scipt code for this UI action or some thing new.

 

AshishKMishra_1-1715699300335.png

 

Refer the below thread

https://www.servicenow.com/community/itsm-forum/how-to-disable-all-the-mandatory-fields-using-single... 

 

-Thanks,
AshishKM

 

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

We use a custom Cancel Change Request UI action, not the OOO version.   Based on the article you provided, it appears we are using the correct script command (g_form.checkMandatory = false;), but it doesn't seem to apply to mandatory fields on a different tab within the CR.  Do I need to call out the specific tab in my script (not even sure that is possible)?