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

Alp Utku
Mega Sage

You can use "Selection Required" checkbox while creating the checkbox variable. Please see the screenshot below

 

Checkbox.jpg

Sam M3
Tera Contributor

I have tried that but it didn't work. but I have used another solution to use container variables to separate each checkbox. it works 

Shraddha Kadam
Mega Sage

Hello @Sam M3 ,

 

Please use below script and check if it's work :

function onSubmit() {
/*******************************************************
/* Purpose: Check to make sure that the user has selected
/*    a checkbox on the Record Producer before submitting
/*    and cancels the submission if none of the checkboxes
/*    are checked
/******************************************************/
    var cbx_equipment = g_form.getValue('equipment');
    var cbx_job_restructuring = g_form.getValue('job_restructuring');
    var cbx_leave = g_form.getValue('leave');
    var cbx_reader_or_interpreter_services = g_form.getValue('reader_or_interpreter_services');
    var cbx_reassignment = g_form.getValue('reassignment');
    var cbx_schedule = g_form.getValue('schedule');
    var cbx_workplace_modification = g_form.getValue('workplace_modification');
    var cbx_workplace_policy = g_form.getValue('workplace_policy');
    var cbx_amended_working_hours = g_form.getValue('amended_working_hours');
    var cbx_other = g_form.getValue('other');

    if (cbx_equipment == 'false' && cbx_job_restructuring == 'false' && cbx_leave == 'false' && cbx_reader_or_interpreter_services == 'false' && cbx_reassignment == 'false' && cbx_schedule == 'false' && cbx_workplace_modification == 'false' && cbx_workplace_policy == 'false' && cbx_amended_working_hours == 'false' && cbx_other == 'false') {
        g_form.clearMessages();
        var msg = getMessage("Please select the type of accommodation(s) that you would like");
        g_form.addErrorMessage(msg);
        return false;
    }
}

 

If my answer is useful, please mark my answer helpful and Accept the solution.

 

Thank you.

If my response was helpful, please mark it as correct and helpful.
Thank you.

Hello @Sam M3,

If my answer is useful, please mark my answer as helpful and Accept the solution.

Appreciate your help!

Thank you.

If my response was helpful, please mark it as correct and helpful.
Thank you.

Rahul Kumar17
Tera Guru

Hi Sam,

 

To make a group of four mandatory checkboxes where all of them must be selected before submitting the form, you can use a UI Policy in ServiceNow. Here's how you can do it:

  1. Navigate to the form where the checkboxes are located and click the gear icon in the top-right corner of the form. Select "Configure > UI Policies" from the dropdown menu.

  2. Click the "New" button to create a new UI Policy. Give it a name, such as "Mandatory Checkboxes," and add a short description.

  3. In the "Conditions" section, add the following condition: current.u_checkbox_group == true

    Note: Replace "u_checkbox_group" with the actual name of the checkbox field that represents the group of four checkboxes.

  4. In the "Actions" section, add the following action: current.u_checkbox_1 && current.u_checkbox_2 && current.u_checkbox_3 && current.u_checkbox_4

    Note: Replace "u_checkbox_1," "u_checkbox_2," "u_checkbox_3," and "u_checkbox_4" with the actual names of the four checkbox fields.

  5. Click "Submit" to save the UI Policy.

This UI Policy will make all four checkboxes mandatory and prevent the form from being submitted unless all four checkboxes are selected. When the user tries to submit the form without selecting all four checkboxes, they will see an error message indicating that all four checkboxes must be selected.

 

Thanks,

Rahul Kumar

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar