Checkboxes Mandatory in Service Catalog

pramodkumar
Tera Expert

Hi All,

 

we have four checkboxes on a catalog form checkbox1, checkbox2, checkbox3, checkbox4 . out of checkbox1 and checkbox2 only one of them is mandatory for submission and from checkbox3 and checkbox4 only one of them is mandatory for submission. How can achieve this?

 

Thanks!

5 REPLIES 5

Service_RNow
Mega Sage

Hi @pramodkumar 

try this  below code

 

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;

}

 

https://www.servicenow.com/community/developer-forum/how-can-i-make-a-checkbox-actually-mandatory-in...

Please mark reply as Helpful/Correct, if applicable. Thanks!

Harish KM
Kilo Patron
Kilo Patron

Hi @pramodkumar by default, the checkbox variable will hold false value, so you can write a onsubmit client script to check atleast 1 check box is selected on the combination

function onSubmit() {

var check1 = g_form.getValue('check1');
var check2 = g_form.getValue('check2');
var check3 = g_form.getValue('check3');
var check4 = g_form.getValue('check4');
// for checkbox 1 and 2
    if ( check1 != 'true' && check2 != 'true') {
        alert(" 1 atleast one check box is mandatory");
        return false;
    }
// for checkbox 3 and 4
    if (check3 != 'true' && check4 != 'true') {
        alert("2 atleast one check box is mandatory");
        return false;
    }
}
Regards
Harish

Sagar Pagar
Tera Patron

Hi @pramodkumar,

 

You can achieve using On submit Catalog client scripts. Here is sample scripts -

 

if (g_form.getValue('check_box_1') == false || g_form.getValue('check_box_2') == false) {
alert("Select check box 1 or check box 2");
return false;
}

 

if (g_form.getValue('check_box_3') == false || g_form.getValue('check_box_4') == false) {

alert("Select check box 3 or check box 4");
return false;
}

 

 

Thanks,

Sagar Pagar

The world works with ServiceNow

Hi Sagar,

out of 1 and 2  checkbox only one is required. Users should only select one checkbox and they should not select both. Same with 3 and 4.