Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to disable all the mandatory fields using single function/command.

balaji_prusty1
Giga Guru

Hi All;

In change form   we have lots of mandatory fields depends on the state/type of change. When user need to cancel the change he/she not to ask to fill the mandatory fields depends in which state he/she cancelling.

I can use g_form.setMandatory("FiledName" , false). But again I need to write code for all the mandatory fields (its around 30+) .

Is there any other way to remove/disable all the mandatory fields using single line code.

Thanks in Advance.

Balaji Prusty.

1 ACCEPTED SOLUTION

I am not getting the Close the loop / Answered   under Action....I was looking for this option.



All my previous threads are still open due to this...not sure what/whom need to contact to get this.


View solution in original post

24 REPLIES 24

Anurag Tripathi
Mega Patron
Mega Patron

Use this just before the save or submit.



g_form.checkMandatory = false;  


-Anurag

Hi Anurag;



Thanks it works fine. But I need to make mandatory to one field (Close Notes) except all. But it applying all the field.



I used like this below but it not asks to fill close notes while saving.



g_form.checkMandatory = false;

g_form.setMandatory('close_notes', true);


Hi Balaji,



You may find below thread helpful.


Saving a record without populating all mandatory variables


g_form.checkMandatory = false;   will make these fields non mandatory from the form, client side. You can add a data policy that will make close_notes mandatory. Data policies will still mandate the field . I think this should work.


-Anurag