- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2020 10:47 PM
Hi All,
I have a requirement for a catalogue item to make atleast one variable( out of three different variable type fields) to be set as mandatory initially and when one of those three variables are answered, then the other two need not be mandatory. Please help me how to achieve this( UI Policy / catalog client script). Thank you.
The above three variables are displayed when " Yes" is selected for a Yes./No Variable.
Three variables are:
1. Variable Question: Sample text field
Name: sample_text
2.Variable Question: Sample Reference Field
Name: rf_field
3. Vaiable Question: Sample Multi Line Text
Name: mutliline_text
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2020 12:20 AM
Try onSubmit client script
var a = g_form.getValue("sample_text");
var b = g_form.getValue("rf_field");
var a = g_form.getValue("mutliline_text");
if(a == "" && b == "" && c == "") {
alert("Kindly fill any one of these field");
return false; }

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2020 11:20 PM
Hi,
Using the Catalog OnChange Client script you can achieve this use case.
1)Initially out of 3 variable 1 var is mandatory.
2)One of those 3 variables are answered then 2 variable is not mandatory.
Client script OnChange()
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
g_form.setMandatory(Var1, true); // 1)Initially out of 3 variable 1 var is mandatory.
return;
}
if(g_form.getValue('var1') != "")
{
//2)One of those 3 variable are answered then 2 variable is not mandatory.
g_form.setMandatory(var2, false);
g_form.setMandatory(var3, false);
}//end if
else if(g_form.getValue('var2') != "")
{
g_form.setMandatory(var1, false);
g_form.setMandatory(var3, false);
}//end else if
else //for var 3
{
g_form.setMandatory(var1, false);
g_form.setMandatory(var2, false);
}//end else
}
Thanks,
Kunal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2020 12:16 AM
Hi Kunal,
Thank you for your reply!
Unfortunately it didn't work, as the first variable is displayed as mandatory without selection of boolean(Yes/No) variable.
Sorry for the confusion in my question. Actually all the variables should be displayed as mandatory for the Boolean(Yes/No) variable. So when one of the three variables is answered, then other two variables should be set as non-mandatory. Below is the client script I've used. Your response is much appreciated. Thank you.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.setMandatory('sample_text', true); // 1)Initially out of 3 variable 1 var is mandatory.
return;
}
if(g_form.getValue('sample_text') != "")
{
//2)One of those 3 variable are answered then 2 variable is not mandatory.
g_form.setMandatory('rf_field', false);
g_form.setMandatory('multiline_text', false);
}//end if
else if(g_form.getValue('rf_field') != "")
{
g_form.setMandatory('sample_text', false);
g_form.setMandatory('multiline_text', false);
}//end else if
else //for var 3
{
g_form.setMandatory('sample_text', false);
g_form.setMandatory('rf_field', false);
}//end else
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2020 12:09 AM
Hi Kunal,
Thank you for your reply!
Unfortunately it didn't work, as the first variable is displayed as mandatory without selection of boolean(Yes/No) variable.
Sorry for the confusion in my question. Actually all the variables should be displayed as mandatory for the Boolean(Yes/No) variable. So when one of the three variables is answered, then other two variables should be set as non-mandatory. Below is the client script I've used. Your response is much appreciated. Thank you.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.setMandatory('sample_text', true); // 1)Initially out of 3 variable 1 var is mandatory.
return;
}
if(g_form.getValue('sample_text') != "")
{
//2)One of those 3 variable are answered then 2 variable is not mandatory.
g_form.setMandatory('rf_field', false);
g_form.setMandatory('multiline_text', false);
}//end if
else if(g_form.getValue('rf_field') != "")
{
g_form.setMandatory('sample_text', false);
g_form.setMandatory('multiline_text', false);
}//end else if
else //for var 3
{
g_form.setMandatory('sample_text', false);
g_form.setMandatory('rf_field', false);
}//end else
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2020 12:20 AM
Try onSubmit client script
var a = g_form.getValue("sample_text");
var b = g_form.getValue("rf_field");
var a = g_form.getValue("mutliline_text");
if(a == "" && b == "" && c == "") {
alert("Kindly fill any one of these field");
return false; }