How to repeat catalog variables?

Srini19
Tera Contributor

Hi,

Have use case which need to repeat the previous variables in service catalog.

For Example:

My catalog has 46 variables:

Based on the input given as yes on 46 th variable I need to repeat the variables from 33 to 46 again. Please let me know how we can achieve this.

 

Thanks

Srini

6 REPLIES 6

Hitoshi Ozawa
Giga Sage
Giga Sage

Not sure what's the question is asking. Is the question about creating variables on the form or about showing/hiding variables based on selection on the 46th variable?

If the question is about defining variables on a form, define variable 33 but instead of pressing the "Update" button, right click on the head area and select "Save". Change the "Name" and "Order". Right click on the header area and select "Insert". Repeat for variables 34 to 46.

If the question is about showing/hiding variables, the easiest way I know is to name fields "field1" to "field46" and then to use client script to show/hide variables. By "repeat", is there going to be 60 fields when the variable 46 is true? If so, create variables named field1 to field60 and create an onChange() on variable 46.

For example:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var display_flg = (newValue == 'Yes'); // When the variable type is "Yes/No"
    for (var i = 47; i <= 60; i++) {
        g_form.setDisplay('field' + i, display_flg); // show and hide variables
    }

}

If the variable names can't be named consecutively, use the following script.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var display_flg = (newValue == 'Yes');  // When the variable type is "Yes/No"
    var variable_list = ['variable47', 'variable48'];  // list of variable names to show/hide
    for (var i = 0; i <= variable_list.length; i++) {
        g_form.setDisplay(variable_list[i], display_flg);
    }
}

Hitoshi Ozawa
Giga Sage
Giga Sage

@Srini19 @deeks Should be using Variable Sets. Instead of the last question, let user add a new row in the Variable Set for the new item.