Catalog UI Policy /w Script: Show variable only, if value from another variable matches reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2023 06:44 AM
Hi community!
I am currently struggling with a variable (Lookup Select Box) that I only want to show, based on the selected value from another variable field (also Lookup Select Box).
The logic in the two variables is, that the first variable represents names for regions ("teams_suffix"). The second variable represents areas ("ms_teams_sub_suffix"), that are within these regions. In the areas table, I have a reference field on the region table.
Now, some of the regions have areas, others don't. So if a region has no areas underneath, I don't want the Lookup Select Box for "areas" to display. Also, only if the user has selected a different value then "-- None --", the area variable should show up.
What I have currently done is, to manually select the regions, that have areas underneath within the Condition of the Catalog UI Policy. So if the variable for the region is set to a matching value, Catalog UI Policy Actions sets the "areas" variable to visible.
So you can guess - the logic i applied is not dynamically. I have to manually edit the Catalog UI Policy condition, everytime I update the tables. My idea was to solve this problem via scripting.
So I tried:
Setting the Catalog UI Policy Condition to "teams_suffix" is -- NONE --
Catalog UI Policy Action
Then I inserted the scripts:
Execute if true
function onCondition() {
g_form.setVisible('ms_teams_sub_suffix', false);
}
Execute if false
function onCondition() {
var region = g_form.getValue('teams_suffix');
var areas = new GlideRecord ('u_ms_teams_sub_suffix');
areas.addQuery('ms_teams_suffix',region);
areas.query();
while(areas.next()){
g_form.setVisible('ms_teams_sub_suffix', true);
}
}
But my second variable never shows up on the Catalog Item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2023 12:26 AM
On UI Policy the UI Policy Action says what happens when the condition is true. The reverse if false option reverses what happens if condition is false.
So in your case if "teams_suffix" is none, then the field "ms_teams_sub_suffix" is hidden and it's shown if the teams_suffix is anything other than none.
So if you want to use the script you should delete the UI Policy Action since that might not behave well with the scripts touching the same fields.
Also, since you're using client side functionalities, you shouldn't use GlideRecord directly and instead call a GlideAjax script include instead.