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.

Hide Variable based on Select Box choices

David Boom
Tera Contributor

I have a select box variable with multiple choices, I need to show other variables based on select box choices.

  • If choice A is selected, variable AB and AC should be visible.
  • If choice B is selected, only variable AB should be visible.

Am able to achieve the condition through onChange client script but when I select A first and then B, it is not hiding AC.

 

if(choice == "A"){

g_form.setVisible('AB', true);

g_form.setVisible('BC', true);

}

 

if(choice == "B"){

g_form.setVisible('AB', true);

}

14 REPLIES 14

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @David Boom 

 

Look like your code is half

 

https://www.servicenow.com/community/itsm-forum/hide-show-select-box-variable-based-on-the-another-s...

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Medi C
Giga Sage
Giga Sage

@David Boom 

You won't need to script, please use UI Policies instead

First one: 

Condition: Choice != A (Choice is not A)

Reverse if false = True

 

UI Policy Action:

- Field: AB.  Visible = Fasle, FieldAction = ClearValue

- Field: AC.  Visible = Fasle, FieldAction = ClearValue

 

Second one:

Condition: Choice != B (Choice is not B)

Reverse if false = True

 

UI Policy Action:

- Field: AB.  Visible = Fasle, FieldAction = ClearValue

 


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @David Boom 

 

Do it via UI policy that is low code and easy.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Medi C
Giga Sage
Giga Sage

If there is no escape from Client Script, you should take care of the negation as well:

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

    // Show variables based on the selected choice
    if (newValue == 'A') {
        g_form.setVisible('AB', true);
        g_form.setVisible('AC', true);
        return;
    } 
     if (newValue == 'B') {
        g_form.setVisible('AB', true);
        g_form.setVisible('AC', false);
        return;
    }
}

 


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

@David Boom 

 

I hope you are doing well!

Did it work ? Was my reply helpful?


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.