How to make atleast one variable mandatory out of three different variables(Single Line Text, Reference Field, Multi Line Text fields) in a service catalog?

Anil Kumar Koth
Tera Contributor

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

 

1 ACCEPTED SOLUTION

mr18
Tera Guru
Tera Guru

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; }

View solution in original post

6 REPLIES 6

Kunal Varkhede
Tera Guru

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

 

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

}

 

Anil Kumar Koth
Tera Contributor

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

}

mr18
Tera Guru
Tera Guru

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; }