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.

on changing choice, checkbox should automatically uncheck

prabhmeet
Giga Expert

Hi,

I have created a catalog item, it has a selectbox variable with 4 choices, I want that whenever I change the choices, the Checkboxes variables I have made (Menu and function)  should uncheck.

 

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

if(newValue == 'true'){
g_form.setValue('menu', false);
g_form.setValue('function',false);

}}

 

 

 

1 ACCEPTED SOLUTION

Community Alums
Not applicable

If you want it to be unchecked when ever the choice is changed remove the if condition

 

 

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

 

g_form.setValue('menu',false);

g_form.setValue('function',false);


}

 

and if you want to it to be unchecked only if a patricular choice is selected use the below code

 

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

var c=g_form.getValue('contact_type');// replace the 'contact_type' with your field name

if(c=='')// enter the choice which you want to trigger

{

g_form.setValue('menu',false);

g_form.setValue('function',false);

}
}

View solution in original post

9 REPLIES 9

Community Alums
Not applicable

Hi

your requirement is not clear what you want to achieve?

Hi,

I want that whenever request type value changes, the Menu and Function checkbox should uncheck. I have written the following script but its not working.

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

if(newValue == 'true'){
g_form.setValue('menu', false);
g_form.setValue('function',false);

}}

Community Alums
Not applicable

change the code

 

 

 

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

g_form.setVisible('menu',false);

g_form.setVisible('function',false);


}}

I tried it. This is not working, it is hiding both the checkboxes. I want to make them uncheck on changing the choice.