The CreatorCon Call for Content is officially open! Get started here.

how to make field mandatory using script in UI policy

chichu
Kilo Contributor

how to make field mandatory using script in UI policy

8 REPLIES 8

@u r answer correct and before runscript what field to change write a condition to   that field


Yes exactly. For more details use these as a reference :
Creating a UI Policy - ServiceNow Wiki


ServiceNow Developers


SriharshaYe
Kilo Sage

Add the following code to the UI Policy Script section.

g_form.setMandatory('field_name', true); // Make the field mandatory

 eg: g_form.setMandatory('short_description', true); }

// to make the field non-mandatory under certain conditions, you can set false.

g_form.setMandatory('field_name', false);

Kebabdressing
Tera Contributor

I had this same problem, and I found out that you can create a UI Policy with the correct conditions on "When to apply", and then save it. Then you have the possibility to create UI Policy Actions, where you can set which fields you want to be mandatory. This way you don't have to script it.