Change which field are visible or hidden based on select box choice

tkh
Kilo Expert

I am fairly new to Service Now, if not entirely new to scripting, so please be patient with this newby.  

We have several Service Catalogs that all share a core set of fields, then each request has a few additional fields that are related to that specific type of change.   This leaves us with a bunch of Service Catalogs that are 90% the same.   What I had thought about doing would be to make a more dynamic form, that could hide or show fields based on the type of request being selected from a Select Box.

Ideally the form would load with only the Select Box showing, then based on which request type they choose from the Select Box would show the required fields.   I have tried using Catalog UI Policy but running into "There are multiple UI Policies with the same Order for this field - their run order is not predictable" errors then the fields work correctly on one policy but not the next policy.

I also tried using scripts but wasn't able to get the OnChange to work when the selection was changed.

So I am looking for some advice as to the best method to accomplish this.   And thank you in advance for your help.

1 ACCEPTED SOLUTION

Geoffrey2
ServiceNow Employee
ServiceNow Employee

Hi Trudy,



It sounds like your issue is about how to structure your UI Policies.



For example, say you have 3 options in your selectbox, "Request type 1", "Request type 2" and "Request type 3". And you have a Field called "Email" that should only be visible for "Request type 1" and "Request type 3".


You probably have 2 UI Policies affecting this field:


UI Policy 1: Show all fields for Request type 1 (which includes Email)


UI Policy 2: Show all fields for Request type 3 (which also includes Email)



Both of these UI Policies have the same Order and you will see that message. The Order field is not shown on the form out-of-the-box, but it defines the execution order of the UI Policies.



I find that the best way to solve this is to have 1 UI Policy per field:


UI Policy 1: Show Email (Condition is Request type is 1 OR 3)


There are smarter and more effiecient ways to do it, but this (IMHO) is the easiest way to understand and maintain. It usually means more UI Policies, but it's worth it to keep the logic simple.



If you need to have 2 UI Policies for a field, because the times it should be visible and different to the times it should be mandatory (eg, for some requests the field is visible but optional), then I would basically have 2 sets of UI Policies.   Ones that show fields at Order 100, and ones that makes fields mandatory at Order 110. But I would only have 1 UI Policy defining when to show a field, and 1 UI Policy defining when to make it mandatory.


View solution in original post

7 REPLIES 7

This worked beautifully for me!   Took a while to get the initial list of fields set up as we have quite a few, but now that they are it will be easy to add new fields, and add new options to view them with so adding new options and forms shouldn't take too much time and effort.   Thank you!!!!!



I even finished my proof of concept example before today's meeting!


This solution worked for a 3x multiple variable to enforce what is show from three separate variable sets on the catalog item.

Thank you!

mahnooshhenshaw
Kilo Contributor

I am also new and I create question one with select choice. Base on the select choice , I want the next question shows the other set box of  question. I do not have scripting skills how can I do that