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

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

This is expected behavior. When adding multiple checkboxes after each other, they are automatically grouped. Also read:

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

 

The article does mention a workaround involving containers. What you might also do, create an onSubmit Client Script which checks if every checkbox variable is true or not.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

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

 

hi the script doesnt work for me. anything i did wrong?

 

HafilaHatta_0-1719211747595.png

 

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