Make group of checkboxes mandatory

Sam M3
Tera Contributor
Hi, I'd like to create a group of four mandatory checkboxes, where all of them must be selected before submitting the form. I've attempted to use UI actions, but it hasn't been successful. I would appreciate any suggestions for achieving this. Here's the layout of the checkboxes: I verify that I have: [ ] reviewed [ ] Included [ ] Provided [ ] Tested
9 REPLIES 9

AnveshKumar M
Tera Sage
Tera Sage

Hi @Sam M3 ,

You can either use UI Policy with UI Policy Actionss or Client Script.

 

If you want to make them mandatory onLoad or onChange of a specific field, write a client script accordingly and set the order to highest value.

In the client script use,

g_form.setMandatory('field_name', true);

Let me know if you need any more help on this.

 

Thanks,

Anvesh

Thanks,
Anvesh

DUGGI
Giga Guru

You can achieve this requirement by using a Business Rule in ServiceNow.

  1. Create a new Business Rule on the Incident table.
  2. Set the "When to run" field to "Before" and "Insert".
  3. Set the "Advanced" field to "true".
  4. Add the following script in the "Advanced" field:
(function executeRule(current, previous /*null when async*/) {
  var mandatoryFields = ['u_reviewed', 'u_included', 'u_provided', 'u_tested'];
  var isAllSelected = true;

  mandatoryFields.forEach(function(field) {
    if (gs.nil(current.getValue(field))) {
      isAllSelected = false;
      return;
    }
  });

  if (!isAllSelected) {
    gs.addErrorMessage("Please select all mandatory checkboxes.");
    current.setAbortAction(true);
  }
})(current, previous);

This script checks whether all mandatory checkboxes are selected. If any of the checkboxes is not selected, it will add an error message and abort the submit action.

  1. Save the Business Rule.

Sam M3
Tera Contributor

I tried creating the BR with the code. it didn't work. It still submits the form without all checkboxes selected

Ankur Bawiskar
Tera Patron
Tera Patron

@Sam M3 

so it's a normal form?

what script you used in UI action? please share that

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader