Dependent Catalog UI Policies

jmiskey
Kilo Sage

I have a bunch of variable on my Catalog Item, but I have two in particular I want to focus on.  Let's call then "varA" and "varB".  "varA" is only to be displayed if a whole bunch of conditions are met.  "varB" should be displayed if (and when) "varA" is populated with a value.

 

Typically, when I set up Catalog UI Policies where I am showing/hiding fields based on conditions, I opt to set the condition on when to hide the variable.  Then I can make use of the "Clear the variable value" feature on my Catalog UI Policy Action whenver the value is hidden, it is also cleared.  So this how I set up the Catalog UI Policy for "varB".  My condition is "varA" is empty, and the UI Action is to hide/clear "varB".

 

The problem I am having is with Catalog UI Policy for when to show/hide "varA".  It is very complex.  I know how to code it for when to show "varA", but I cannot figure out how to hide it instead, so I can make use of the "Clear the variable value" feature.  Here is what the conditions to show "varA" look like:

jmiskey_0-1675367151201.png

As you can see, there are 4 sets of 3 "AND" conditions, and if any one of those 4 sets of 3 is met, "varA" should be shown.  The issue is, I do not know how to reverse these conditions to change it to the "hide" conditions.  I know how to do it mathematically, but it gets rather messy and the options in this condition builder seem like they may be too limiting (I need to nest down a few levels).

 

I can think of two options:

1. Try to reverse the conditions shown above (my preferred option, because then I could do it with a Catalog UI Policy).  I am just not sure how to do this.

2. Try to create some sort of Script that would automatically clear the value of "varA" whenever it is hidden.  Only, I am not sure where or how to write this script, as it could be triggered by the update of a whole bunch of different variables (since there are so many pieces to the condition).  I really do not want to write the same Catalog Client Script for 7 different Variable changes!

 

Does anyone have any good solutions to this conundrum?

 

Thanks

 

 

3 REPLIES 3

OlaN
Giga Sage
Giga Sage

Hi,

I agree with your first choice, it seems a lot easier to reverse the logic then to script this with a whole lot of variables to account for.

But if you feel that it is too complicated to reverse the conditions you could script just the part of clearing the value by activating the run scripts in the UI policy, and in the script section enter this:

 

g_form.clearValue('variable_name');

 

 

Make sure the script runs for the correct environment, and put it in either the run if true or run if false depending on your requirement.

Example below

script-in-ui-policy.png

Thanks for the reply, but I am not if that helps.  I am a little unclear on these "Run Scripts".

Are the "Run Scripts" replacing the "When to Run" condition, or the "Catalog Policy UI Actions"?

It does not seem to have the desired effect, regardless of what I try.

 

Let's take a step back.  Is it possible to reverse the Conditions I currently have?  Maybe it can be done, and I just don't understand the technique.

Basically, the structure I currently have for "Show" is like this (if I assign a letter to each criterion):

(A and B and C) or (A and D and E) or (A and D and F) or (A and D and G)

 

So to change those to conditions for "Hide", according to the rules of logic (if I recall correctly), I have to put a NOT in front of each criterion, change all ANDs to ORs and all ORs to ANDs.  So that would make my structure look like:

(!A or !B or !C) and (!A or !D or !E) and (!A or !D or !F) and (!A or !D or !G)

 

But in the ServiceNow condition builder, when you want to add groups or clauses, it only seems to allow you to add OR clauses, not AND clauses.

 

 

jmiskey_1-1675374307361.png

So it seems that you can nest AND/OR grouping inside of OR clauses, but you cannot nest AND/OR groupings inside of AND clauses, which is what I need to do if I have to reverse it.

 

Any thoughts?

 

Wow, I just typed up a whole response and it disappeated when I tried to post it!

 

I cannot get your suggestion to work, but I am a little confused on how the Run Scripts work.  Is the script meant to replace the "When to run" conditions, or the "Catalog UI Policy Actions"?  

 

If we can take a step back, maybe we can get the conditions reversed to work for the Hide instead of the Show.  Maybe I am just unaware of how to do it.  

 

Right now I have this structure:

(A and B and C) or (A and D and E) or (A and D and F) or (A and D and G)

and if I understand the rules of logic, in order to reverse them, you need to negate each piece like this:

(!A or !B or !C) and (!A or !D or !E) and (!A or !D or !F) and (!A or !D or !G)

 

But when building the conditions, it appears you can do multiple grouping separated by OR, but not by AND (see below):

jmiskey_0-1675375111460.png

See how there is only the option to add OR clauses at the top?

And idea on how I can create four 4 clauses, like I need to have?

 

Thanks