Best way to show/hide fields on a catalog item

mballinger
Mega Guru

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!

1 ACCEPTED SOLUTION

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

LinkedIn

View solution in original post

10 REPLIES 10

Harsh Vardhan
Giga Patron

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. 

-O-
Kilo Patron
Kilo Patron

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.

Gaurav Shirsat
Mega Sage

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

find_real_file.png

Create New UI Policy by clicking on New button.

You have to add necessary details and save it.

find_real_file.png

after saving the form you will get UI Policy Action Tab where you need to add variable which you want to make read only.

find_real_file.png

also you can make use of Catalog Client Script:- Make type as onLoad

see below

find_real_file.png

Please Mark Correct and Helpful
Thanks and Regards
Gaurav Shirsat