Making a SC hidden variable (reference) mandatory once it is visible

IdeaGuy
Tera Contributor

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.

 

 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

 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.

BradBowman_0-1699131397231.png

BradBowman_1-1699131474189.png

 

 

View solution in original post

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

 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.

BradBowman_0-1699131397231.png

BradBowman_1-1699131474189.png

 

 

DanielCordick
Mega Patron
Mega Patron

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 

IdeaGuy
Tera Contributor

Brad and __DC, thanks for your help!  I was initially blind to the reference to making it mandatory on that form.