We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Need to to show only one(out of 3) select box value if i select check box

Purushotham9963
Tera Contributor

Hi Experts ,

I am trying to create catalog client script for variable creation , i tried number of scripts but did not get any solution 

Can some one help me on this

 

variable type: Check box

1)Hin

2)Her

3)Ucr

 

variable type: select box

1)admin

2)itil

3)test

 

Condition: 

1)When Hin & Her are selected, admin, itil  should populate

2)when Hin & Her & Ucr selected admin, itil, test should populate

3)when Ucr selected  only test should populate 

 

 

Thanks in advance 

1 REPLY 1

Not applicable

Hello @Purushotham9963 

function onChange(control, oldValue, newValue) {
    // Define the checkbox variable names
    var hinChecked = g_form.getValue('checkbox_variable_hin') === 'true';
    var herChecked = g_form.getValue('checkbox_variable_her') === 'true';
    var ucrChecked = g_form.getValue('checkbox_variable_ucr') === 'true';

    // Define the select box variable name
    var selectBox = 'select_box_variable_name';

    // Clear current options
    g_form.clearOptions(selectBox);

    // Populate options based on conditions
    if (hinChecked && herChecked && ucrChecked) {
        g_form.addOption(selectBox, 'admin', 'Admin');
        g_form.addOption(selectBox, 'itil', 'ITIL');
        g_form.addOption(selectBox, 'test', 'Test');
    } else if (hinChecked && herChecked) {
        g_form.addOption(selectBox, 'admin', 'Admin');
        g_form.addOption(selectBox, 'itil', 'ITIL');
    } else if (ucrChecked) {
        g_form.addOption(selectBox, 'test', 'Test');
    }
}

// Use this function to set up the onChange event for your checkboxes
function onLoad() {
    // Call onChange for all relevant checkboxes to initialize the select box
    onChange(null, null, null);
}

// Call the onChange function on checkbox change
g_form.setOnChange('checkbox_variable_hin', onChange);
g_form.setOnChange('checkbox_variable_her', onChange);
g_form.setOnChange('checkbox_variable_ucr', onChange);

 

These script might be helpful for your scenario.

Please hit on the helpful button.
Thank you.