Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to limit the selection of choice list up to 3 in checkbox

Sai Akhil
Tera Contributor

Hello Developers,

I have a requirement where I used 6 checkboxes in the catalog item, but I have to restrict the user to select the utmost 3, please let me know how to achieve this.

Thanks in advance,

Akhil.

5 REPLIES 5

afraz
Giga Guru

create 6 onChange scripts on the 6 checkboxes and add the below code in all

    var checkbox = ['checkbox1', 'checkbox2', 'checkbox3','checkbox4','checkbox5','checkbox6'];
    var chkarr = {};
	var count= 0;
	for(var i=0;i<checkbox.length;i++){
		chkarr[checkbox[i]] = g_form.getValue(checkbox[i]);
	}
	for (var key in chkarr){
		if(chkarr[key] == 'true'){
			count = count + 1;
		}
		if(count == 3){
			for (var key1 in chkarr){
				if(chkarr[key1] == 'false')
				g_form.setReadOnly(key1,true);
			}
		}
		else{
			for (var key1 in chkarr){
				g_form.setReadOnly(key1,false);
			}
		}
	}