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.

Client Script to auto set checkbox if other checkbox is checked

Brandon R1
Tera Contributor

I'm needing a Catalog Client Script that will automatically place a checkmark in a checkbox variable B when checkbox variable A is check marked.

This probably sounds relatively easy but I am not a heavy coder and not sure where to start.

Thanks,

Brandon

1 ACCEPTED SOLUTION

You will need to add '' around the true since this is not a boolean. 

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

if(newValue == 'true'){
g_form.setValue('checkBoxB', 'true');
}

}

 

Try this and see what you get

View solution in original post

6 REPLIES 6

James M
Giga Contributor

Could probably do an onChange client script tied to the first checkbox. Then test if the first checkbox is true. Something like the below should work.

 

if (g_form.getValue('fieldName') == true){

g_form.setValue('secondField',true);

}

Isaac Vicentini
Mega Sage
Mega Sage

You can do it like this:

find_real_file.png

 

Script:

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}

	if(newValue == true){
		g_form.setValue('checkBoxB', true);
	}

}

Best regards,

Isaac Vicentini
MVP 2025


If my answer was helpful, mark it as Helpful or Accept as Solution.

Thanks but this did not work. Once I placed a checkmark in the checkbox variable A, checkbox variable B did not automatically get a checkmark.

 

You will need to add '' around the true since this is not a boolean. 

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

if(newValue == 'true'){
g_form.setValue('checkBoxB', 'true');
}

}

 

Try this and see what you get