How to disable mandatory fields

kmathis
Kilo Contributor

I have configured mandatory fields for our Change form through UI Policy.   I now need to configure a UI Action to cancel the change.   Upon choosing this Cancel menu option, we are currently prompted regarding the mandatory field requirements.   How can I disable the mandatory fields through this UI Action.   Below is my feeble attempt which is currently not working (I only added one field for testing):

function cancel (){

      if(g.form.getValue('short_description')=="")

              g_form.setMandatory('short_description, false');

}

//Canceled state  

var recordState = current.state.getDisplayValue();  

current.state = 4;

// update all the waiting approval to not longer required  

var gr = new GlideRecord('sysapproval_approver');  

gr.addQuery('sysapproval', current.sys_id);  

gr.query();      

if(gr.next()){  

do {  

      if(gr.state == 'requested') {  

          gr.state = 'Canceled';  

          gr.comments = 'The change has been canceled. Your approval is no longer required.'  

          gr.update();  

      }  

gs.eventQueue("change.approver.canceled", gr, gr.approver.getName(), gs.getUserName());  

} while (gr.next())  

}  

current.approval = 'Canceled';

     

moveToCancel();

      function moveToCancel(){

              current.update();

      action.setRedirectURL(current);

                      current.moveTo("Canceled")

}

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi Kari,



Create a UI action with the "action name" field set to sysverb_cancel.



It will then ignore the mandatory fields and do what you need.



For what it's worth, place this in the form context menu so people don't accidentally click it instead of Update or some other button.



UI Actions - ServiceNow Wiki


View solution in original post

5 REPLIES 5

Sheeba_Sriniva1
ServiceNow Employee
ServiceNow Employee

Hi Kari,



Re: How to disable all the mandatory fields using single function/command. post might be helpful.



Thanks


Sheeba Srinivasan


Chuck Tomasi
Tera Patron

Hi Kari,



Create a UI action with the "action name" field set to sysverb_cancel.



It will then ignore the mandatory fields and do what you need.



For what it's worth, place this in the form context menu so people don't accidentally click it instead of Update or some other button.



UI Actions - ServiceNow Wiki


Thank you!   This worked perfectly and yes, it is just in the context menu.


Hi Chuck,

It's working fine on Native view. but not working in Portal. 

Is there any alternate way to achieve this. 

Thanks,

Vivek