Make group of checkboxes mandatory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2023 04:55 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2023 06:29 PM
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
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2023 06:42 PM
You can achieve this requirement by using a Business Rule in ServiceNow.
- Create a new Business Rule on the Incident table.
- Set the "When to run" field to "Before" and "Insert".
- Set the "Advanced" field to "true".
- 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.
- Save the Business Rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2023 11:34 PM
I tried creating the BR with the code. it didn't work. It still submits the form without all checkboxes selected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2023 12:08 AM
so it's a normal form?
what script you used in UI action? please share that
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader