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

That worked!  Thanks, Kris.

Also, thank you @Isaac Vicentini for the initial script.

 

vinay v
Tera Contributor

Hi you can do this it will helps you

onChange() script set table name and field as checkboxA

Script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    if (g_form.getBooleanValue('checkboxA', true)) {
        g_form.setValue('checkboxB', true);
    } else {
        g_form.setValue('checkboxB', false);
    }
}