If you want to run a subworkflow multiple times by passing different values for its parameters or attributes in every subsequent run, you can insert a Foreach element in the parent workflow.

When you insert a Foreach element, you must bind at least one input parameter or attribute as an iterator of type array over which the subworkflow runs. An iterator element can have different values for each subsequent workflow run.

If the subworkflow has output parameters, you should bind the output parameters of the Foreach element as iterators, so that the subworkflow can iterate over them as well.

Caution

If you do not bind the output parameters of the Foreach element as iterators, the subworkflow overrides their values with new values, every time it runs. As a result, the output parameters contain only the result from the last run of the subworkflow.

Open a workflow for editing in the workflow editor.

1

In the workflow editor, select the Schema tab.

2

From the Generic menu, drag a Foreach element in the workflow schema.

3

Select a workflow from the Chooser dialog box.

4

Right-click the Foreach element and select Synchronize > Synchronize presentation.

A confirmation dialog box appears.

5

Click Ok to propagate the presentation of the Foreach element to the current workflow.

A dialog box that displays information about the outcome of the operation appears.

6

On the Inputs tab, verify that the subworkflow's parameters are added as elements of type array.

7

Bind the output parameters of the Foreach element as iterators.

a

On the Schema tab, click the edit icon (Edit icon) of the Foreach element.

b

Select the OUT tab of the Foreach element.

c

Click not set next to a local parameter.

d

Select Bind as iterator.

You can select Bind as iterator to indicate that the subworkflow must iterate over this parameter or attribute.

e

Click Create parameter/attribute in workflow.

The parameter type must be array so that the subworkflow iterates over the values of this array.

f

Select Create workflow OUTPUT PARAMETER with the same name and click Ok.

8

On the Outputs tab, verify that the subworkflow's parameters are added as elements of type array.

You defined a Foreach element in your workflow. The Foreach element runs a workflow that takes as parameters every element from the array of parameters or attributes that you have bound as iterators.

For parameters or attributes that are not defined as arrays, the workflow takes the same value in every subsequent run.

You can use a Foreach element to rename several virtual machines at once. You have to insert a Foreach element in a workflow and bind the vm and the name parameters as iterators. In this way, when you run the workflow, you specify the virtual machines to rename and the new names for the virtual machines. The virtual machines are included as elements in the array that you created for the vm parameter. The new names for the virtual machines are included in the array that you created for the name parameter.