
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Service Catalog gives you a great tool to control variables defined on the catalog item via Catalog UI Policy. But with so many options available, developers get confused when to use what and how to get things done. You can do a lot with Service Catalog UI Policies but there are some best practices you should be aware of, as well as debug tactics in Catalog UI Policies, before you start.
Some things you should know about Catalog UI Policies:
- Running Catalog UI Policy on conditions other than variables
- Running a Catalog UI Policy Action on a Variable Set
- Running a UI Policy on a Variable Set based on the Catalog Item
- How to debug a Catalog UI Policy when it is not working
- Common mistakes developers do in Catalog UI Policy
First, I assume, as developers, you know what a Service Catalog Item is, including what variables and variable sets are. If not, the rest of this post may not make sense and you may want to see Service catalog items and Service catalog variables before proceeding.
Catalog UI Policy secrets that the documentation doesn't tell you (Shhh...)
You can Create a UI policy for catalog items as an easy way to control variables. If I want to show select variables, hide certain variables, and/or make some variables readonly or mandatory, or conditional, you can use a Catalog UI Policy. The best part is, that all these can be done without a single line of coding!!!
Running Catalog UI Policy on conditions other than variables
You cannot run a Catalog UI Policy on conditions other than variables. Catalog UI Policies work on variables only. So even on conditions, it works on variables. Even though I can select other values in the condition builder, the conditions are not evaluated. We are working on this and in future releases we are planning to remove all fields which have no significance to Catalog UI Policies.
Running a Catalog UI Policy Action on a Variable Set
You can run a Catalog UI Policy Action on a Variable Set, but will require some coding. In the base system, we support variables only in action, so you will not be able to select any variable set in catalog ui policy action. You can achieve the outcome with a script.
In Catalog UI Policy after you define the conditions under 'When to Apply' section, there is a section for Script.
It has two entries for 'Execute if true', 'Execute if false'. So you can write scripts when the condition evaluates to true and false.
Use the following script to hide a Variable Set in either place based on the requirement.
g_form.setDisplay('Variable Set Name', false);
Here Variable Set Name is the name of the variable set while it is defined.
This way the entire Variable Set can be hidden via Catalog UI Policy.
Running a UI Policy on a Variable Set based on the Catalog Item
You cannot run a UI Policy on a Variable Set based on the Catalog Item. This is not supported as of today because Catalog UI Policy conditions works only on variables, so it will not evaluate conditions on Catalog Item. You can achieve same via Catalog Client Script. Here is a small script which can be added to Catalog Client Script which will do the work:
function onLoad() {
if(g_form.getUniqueValue() == '<sys_id of the item>') {
g_form.setDisplay('<Variable Set Name', false)
}
}
The placeholders for <sys_id of the item> and <Variable Set Name> needs to be replaced with your use case. Also note g_form.getUniqueValue() gives sys_id of Request Item or Catalog Task, so please update the code accordingly.
Debug a Catalog UI Policy that is not working
From Helsinki release we do provide very easy way to debug Catalog UI Policy. Here is a small video on how to enable and make use of the debug feature.
Common mistakes developers make using a Catalog UI Policy
Common Mistake #1: Make a variable mandatory via one catalog ui policy, and then make the same variable readonly via another catalog ui policy. In this case, users will be able to submit item form because variable will be read-only and mandatory for them.
Common Mistake #2: Make a variable mandatory via one catalog ui policy, and then make the same variable hidden via another catalog ui policy. In this case users will not see the variable and also will not be able to order the item.
Common Mistake #3: Having a conflicting Catalog UI Policy and Catalog Client Scripts. Catalog Client Scripts runs last, so it will override changes done by Catalog UI Policy.
- 3,915 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.