Conditionally mandatory fields

johnsgp
Mega Expert

I have some fields of a table which I want to be mandatory under certain conditions only.

To do this on a form, I can write a client script which does g_form.setMandatory or I can write a UI Policy.

What about if I want to do this on a list?   What is the best practice for making fields conditionally mandatory so that list edits will fail if the conditionally-mandatory fields are blank?

Concrete example: I want the Department field to be mandatory if the Company field is filled in on the Users table.   If Company is blank, then Department can be blank too.   If I set this up on the form, the policy can be avoided by editing using the list editor instead of the form.

1 ACCEPTED SOLUTION

You can try adding gs.isInteractive condition in your script and that should do the job for you.


GlideSystem - ServiceNow Wiki


View solution in original post

8 REPLIES 8

Anurag Tripathi
Mega Patron
Mega Patron

Create a data policy, its same as ui policy, infact the same ui policy can be converted into data policy too.


Mail difference is that ui policy only runs on a form for any input coming form form but data policy runs everywhere.


-Anurag

As Kalai suggested, Before BR (insert, update) will work just fine.


-Anurag

johnsgp
Mega Expert

I forgot to add one more point: the condition needs to be done in JavaScript because it is too complex for the condition builder.   So a data policy will not help.


Use a before business rule. Abort the action if the data is empty and show some info message to the user.