- 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 06:41 PM
it can be done using catalog UI Policy as well. Please check Catalog UI Policy and try. That should work.
You can make variable, "READ Only", "HIDE" and "Mandatory" using catalog ui policy.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2021 06:43 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2021 07:16 PM
From a maintenance p.o.v. I find it is better to use a UI Policy per variable. Even when it may seems this can lead to too many UI Policies. The advantage being that if one needs to check how a field's behavior is configured one needs to check just in one place or if one needs to modify the behavior of a given field one can do it in just one place.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2021 09:54 PM
Hello
as per the Best Practice of ServiceNow Show/Hide of field must be done using the Catalog UI Policy.
You will find this in Related List of Your Catalog Item. see below
Create New UI Policy by clicking on New button.
You have to add necessary details and save it.
after saving the form you will get UI Policy Action Tab where you need to add variable which you want to make read only.
also you can make use of Catalog Client Script:- Make type as onLoad
see below
Please Mark Correct and Helpful
Thanks and Regards
Gaurav Shirsat