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:47 PM
Hi @David Boom
I think it would be best is you could use UI policy like
choice = A
Policy action
NO need to use client script.
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:04 AM
I have around 25 choices and 100 variables. Using UI policies will create around 1000 UI policy actions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2025 12:07 AM
I agree, but since you're facing issues with using CS, I thought that using a UI Policy might be a better approach—it's no-code and quick to implement.
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:49 PM
try this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Hide all variables initially
g_form.setVisible('AB', false);
g_form.setVisible('AC', false);
// Show variables based on the selected choice
if (newValue == 'A') {
g_form.setVisible('AB', true);
g_form.setVisible('AC', true);
} else if (newValue == 'B') {
g_form.setVisible('AB', true);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader