Hide Variable based on Select Box choices
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2025 11:34 PM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2025 11:50 PM
Hi @David Boom
Look like your code is half
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]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2025 11:52 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2025 12:04 AM
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]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2025 12:29 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2025 03:58 AM
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.