How to make multiple "checkbox" variables mandatory.........

ID NOBLE
Tera Expert

Hello,

 

Please how can I make multiple "checkbox" variables mandatory on a request form. Basically, there are about 6 checkbox variables and each of them must equal to "TRUE" for the form to be submitted. If one or two of those checkbox are not checked, the system must not allow submission until they are all checked. How do I do this please?

 

Thanks in advance.

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@ID NOBLE 

something like this in onSubmit catalog client script

function onSubmit() {
    // List your checkbox variable names here
    var checkboxes = [
        'checkbox_var_1',
        'checkbox_var_2',
        'checkbox_var_3',
        'checkbox_var_4',
        'checkbox_var_5',
        'checkbox_var_6'
    ];

    // Check if all are true (checked)
    for (var i = 0; i < checkboxes.length; i++) {
        if (g_form.getValue(checkboxes[i]).toString() !== 'true') {
            alert('Please check all required checkboxes before submitting.');
            return false; // block submission
        }
    }

    return true; // all checked, allow submit
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi @Ankur Bawiskar ,

 

Thanks for your supports. However, I have tried it but it doesn't work please. Is there any other way we can make it work please?

Thanks

Bhuvan
Mega Patron

@ID NOBLE 

 

Follow below knowledge article

 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0720517

 

If this helped to answer your query, please mark it helpful & accept the solution. 

 

Thanks,

Bhuvan