- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 11:26 AM
I have two variables in a catalog item, the first is a multiple-choice with two options - this field is mandatory and presents this way when viewing the catalog item. The second variable is a reference field to select a user - this field is hidden until someone selects the second option in the aforementioned multiple-choice variable.
I am trying to make this second variable mandatory once it becomes visible however when I test the catalog item, the second item does not appear or act mandatory once visible. I have read elsewhere in the community of a script to make this work, and I have included this script in the Catalog Client Script tab:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (newValue == "visible" && oldValue != "visible") {
g_form.setMandatory("variable_name", true);
}
}
...where variable_name above matches the variable that is made visible.
Other fields on the Catalog Client Script page:
Type: OnChange
Variable Name matches the variable name to be set mandatory when visible
Applies on Catalog Item view: True
Any advice would be appreciated. Thx.
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2023 01:59 PM
Whatever reference post you got this from is complete garbage if this is what it said to do. You cannot detect in a client script if a variable is visible or not. It sounds like what you want to do in this case is remove whatever you have in place to make the second variable visible and create a Catalog UI Policy when the first variable equals the second option, with the Reverse if false box checked. The Catalog UI Policy will then have a Catalog UI Policy Action to make the second variable visible AND mandatory.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2023 01:59 PM
Whatever reference post you got this from is complete garbage if this is what it said to do. You cannot detect in a client script if a variable is visible or not. It sounds like what you want to do in this case is remove whatever you have in place to make the second variable visible and create a Catalog UI Policy when the first variable equals the second option, with the Reverse if false box checked. The Catalog UI Policy will then have a Catalog UI Policy Action to make the second variable visible AND mandatory.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2023 08:35 PM
No script is needed for this. Create a UI policy and set your conditions,
then create a UI olicy action, for the second field, this is where you can set mandatory and visible
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 09:14 AM
Brad and __DC, thanks for your help! I was initially blind to the reference to making it mandatory on that form.