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

@CatalogCat 

Thank you for marking my response as helpful.

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

Regards
Ankur

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

@CatalogCat 

Thank you for marking my response as helpful.

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

Regards
Ankur

 

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

Vaishnavi Lathk
Mega Sage
Mega Sage

please create an on submit client script and use below script ,, make sure to replace the checkbox with your checkbox names 

 

function onSubmit() {
	
	

		
		
		var checkboxes = ['checkbox1', 'checkbox2', 'checkbox3', 'checkbox4'];
		var isSelected = false;
		
		for (var i = 0; i < checkboxes.length; i++) {
			
			if (g_form.getValue(checkboxes[i]) == 'true') {
				isSelected = true;
				break;
			}
		}
		
		if (isSelected == false) {
			g_form.addErrorMessage('At least one  checkbox is required');
			
			return false;
		}
		
	
	
}

 

This is tested in My instance and working.

 

Regards,

Vaishnavi Lathkar 

 

Aman Kumar S
Kilo Patron

Hey @CatalogCat ,

Refer to below article and solution provided by @Joseph Gabriel 

No scripting is required for this:

How to make a group of checkboxes mandatory

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

Best Regards
Aman Kumar

Parth10243
Tera Contributor

Instead of using getValue(), use g_form.getBooleanValue().

getValue function returns string