Mandatory checkbox can be submitted?

Hafila Hatta
Tera Guru

i'm currently developing on washington version, and notice that if you add a few checkbox, these variables are bundled together. now, i want to make these checkboxes mandatory, or else the request cannot be submitted. how can i achieve that?

 

i have set all checkboxes to "Selection Required" but i can still submit request even if i dont select one of them

2 ACCEPTED SOLUTIONS

Pravindra1
Tera Guru

Hi @Hafila Hatta ,

you can write an onSubmit client script as below :

 

function onSubmit() {
if ((g_form.getValue('checkbox_variable1') == 'false') && (g_form.getValue('checkbox_variable2') == 'false') && (g_form.getValue('checkbox_variable3') == 'false')) {
alert('Please Select at least one checkbox');
return false;
}
}

Best Regards,

Pravindra Kumar

 

View solution in original post

Based on what you described, all checkboxes should be true? Now you are checking if all are false, so if only one is true... it won't work. So instead check if one if false. for example:

 

g_form.getValue('checkbox_variable1') == false || g_form.getValue('checkbox_variable2') == false || g_form.getValue('checkbox_variable3') == false

 

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

8 REPLIES 8

thanks for the help, its working now. 

swathisarang98
Giga Sage
Giga Sage

Hi @Hafila Hatta ,

 

Even if you have set all the checkbox to 'selection required' true, it will not make each Checkbox as mandatory, it will bundle all the checkbox together and even if any one is selected, mandatory will be greyed out , 

 

So use a on submit client script to check if all the check boxes  which you want to be mandatory are returning  value as "true" .If yes allow the requestor to submit the catalog item .If not stop the submission.

 

if(g_form.getValue('checkbox_1')==true && g_form.getValue('checkbox_2')==true)
return true;
else
return false;

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

@Hafila Hatta 

Thanks for marking my answer as helpful. If it helped you in any way please accept the solution so that it will be beneficial to the future readers with the same query.

Regards,

Swathi Sarang

Ankur Bawiskar
Tera Patron
Tera Patron

@Hafila Hatta 

please share your screenshot

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