- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2021 06:39 PM
Hello,
I haven't created catalog items in a while. My question is, what is the best way to show/hide variables based off of a selection from a drop down?
I have 10 fields on the item. The first field is a selection with 2 choices. If they select choice 1, it will show the other 9 fields. If I select choice 2, only 7 of the 9 fields will display. What is the best of writing this in a catalog client script?
thanks!
Solved! Go to Solution.
- Labels:
-
Multiple Versions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2021 10:06 PM
Just want to add to this, don't forget to clear the variable values. For example when filling out the form, a user can decide to change variables which cause other variable not to be visible anymore... though those variables will still contain it's contents!
So do use the "Clear the variable value" option, or add scripting to empty the variable. This is an often missed step I see at customers.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2021 10:06 PM
Just want to add to this, don't forget to clear the variable values. For example when filling out the form, a user can decide to change variables which cause other variable not to be visible anymore... though those variables will still contain it's contents!
So do use the "Clear the variable value" option, or add scripting to empty the variable. This is an often missed step I see at customers.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2021 06:21 AM
To hide all fields I was going to create a UI Policy and hide them all of selection is none and then have the following catalog client script
Would I just do:
if(g_form.getValue('u_need_more_docs') == 'yes') {
g_form.setVisible('u_doc_type', true);
g_form.setVisible('u_department', true);
g_form.setVisible('u_division', true);
g_form.setVisible('u_state', true);
g_form.setVisible('u_city', true);
g_form.setVisible('u_zip', true);
g_form.setVisible('u_needed_date', true);
g_form.setVisible('u_delivery_date', true);
g_form.setVisible('u_problem_type', true);
} else {
g_form.setVisible('u_doc_type', false);
g_form.setVisible('u_department', false);
g_form.setVisible('u_division', false);
g_form.setVisible('u_state', false);
g_form.setVisible('u_city', false);
g_form.setVisible('u_zip', false);
g_form.setVisible('u_needed_date', false);
g_form.setVisible('u_delivery_date', false);
g_form.setVisible('u_problem_type', false);
}
if(g_form.getValue('u_need_more_docs') == 'no') {
g_form.setVisible('u_doc_type', true);
g_form.setVisible('u_department', true);
g_form.setVisible('u_division', true);
g_form.setVisible('u_needed_date', true);
g_form.setVisible('u_delivery_date', true);
g_form.setVisible('u_problem_type', true);
} else {
g_form.setVisible('u_doc_type', false);
g_form.setVisible('u_department', false);
g_form.setVisible('u_division', false);
g_form.setVisible('u_needed_date', false);
g_form.setVisible('u_delivery_date', false);
g_form.setVisible('u_problem_type', false);
}
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2021 06:33 AM
Hi,
you can have one if for YES
Another else if for NO
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2021 06:43 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2021 10:06 PM
Hi,
As members have suggested you can use Catalog UI Policy.
If you require complex logic to show/hide which requires scripting then better go with catalog client script
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader