Make at least one checkbox mandatory when there are multiple sets of checkboxes

CatalogCat
Tera Contributor

I have a catalog item with multiple groups of label+checkboxes. Is there a way to make the user check at least one of the boxes in any of the groups? This is easy when we have only one group, but it is possible to make a UI policy that will work across the groups?

1 ACCEPTED SOLUTION

Hi,

you will have to use onSubmit catalog client script and verify that

function onSubmit() {

	var value1 = g_form.getValue('variable_1');
	var value2 = g_form.getValue('variable_2');
	var value3 = g_form.getValue('variable_3');
	var value4 = g_form.getValue('variable_4');
	var value5 = g_form.getValue('variable_5');
	var value6 = g_form.getValue('variable_6');
	var value7 = g_form.getValue('variable_7');
	

	if(!value1 && !value2 && !value3 && !value3 && !value4 && !value5 && !value6 && !value7) {
		g_form.addErrorMessage("Please select at least 1 variabel");
		return false;
	}
	return true;

}

Regards
Ankur

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

View solution in original post

14 REPLIES 14

Really helpful. Thanks

THIS is what I needed.  Thank you!

CatalogCat
Tera Contributor

I know that. But that is not what I am asking. I have several such groups of label+checkboxes:

Label A
Box 1
Box 2
Box 3

Label B
Box 4
Box 5

Label C
Box 6
Box 7

I want to enforce at least one of the boxes 1-7 to be checked, regardless of which group it's in. If Box 7 is ticked, ticket can be submitted, even if none of the boxes under Label A or Label B are checked.

Hi,

you will have to use onSubmit catalog client script and verify that

function onSubmit() {

	var value1 = g_form.getValue('variable_1');
	var value2 = g_form.getValue('variable_2');
	var value3 = g_form.getValue('variable_3');
	var value4 = g_form.getValue('variable_4');
	var value5 = g_form.getValue('variable_5');
	var value6 = g_form.getValue('variable_6');
	var value7 = g_form.getValue('variable_7');
	

	if(!value1 && !value2 && !value3 && !value3 && !value4 && !value5 && !value6 && !value7) {
		g_form.addErrorMessage("Please select at least 1 variabel");
		return false;
	}
	return true;

}

Regards
Ankur

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

@CatalogCat 

You can follow the approach suggested by @Ankur Bawiskar.

 

Thanks and regards,

Kartik