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

Hi Mr,

 

Sorry for delay in response!

Thank you for providing onSubmit Client script for my requirement. It worked.

Hitoshi Ozawa
Giga Sage
Giga Sage

Client Script

function onSubmit() {
    var mandatoryVars = 'sample_text,rf_field,mutliline_text';
    var passed = forceMandatoryCheckboxes(mandatoryVars);
    if (!passed) {
        var message = 'You must enter at least one variable field.';
        g_form.addErrorMessage(message);
        return false;
    }
}

function forceMandatoryCheckboxes(mandatory) {
    mandatory = mandatory.split(',');
    var answer = false;
    for (var x = 0; x < mandatory.length; x++) {
        if (g_form.hasField(mandatory[x])) {
            if (g_form.getValue(mandatory[x]) != '') {
                return true;
            }
        }
    }
    return false;

}

UI Policy:

find_real_file.png