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

Harshal Gawali
Giga Guru

Hello Harshal,

 

Thanks for your kind reply, but that blog will not suffice my requirement, the user does not want to select a minimum of 3  but can select up to 3.  Please let me know if u know how to achieve this.

 

Thanks,

Akhil

Pratiksha Kalam
Kilo Sage

Hello,

You can write client script in catalog item.

https://community.servicenow.com/community?id=community_question&sys_id=f001b8a7dbbe2bc05d782183ca96...

If answer is helpful please mark correct and helpful!
Thanks,
Pratiksha

Pranav Bhagat
Kilo Sage

Hi

Check this samplle code 

var checkboxes = ['checkbox1', 'checkbox2', 'checkbox3', 'checkbox4'];

var count ;

for (var i = 0; i < checkboxes.length; i++) {

if (g_form.getValue(checkboxes[i]) == 'true') {
count = count +1;
break;
}
}

if (count > 3) {
g_form.addErrorMessage('You can't select all');

return false;
}

Regards

Pranav