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.

About this task

When you insert a Foreach element, you must select at least one array over which the Foreach element iterates. An array element can have different values for each subsequent workflow run.

If the subworkflow has output parameters, you should select the output parameters of the Foreach element in which to accumulate workflow outputs , so that the subworkflow can iterate over them as well.

Prerequisites

Open a workflow for editing in the workflow editor.

Procedure

  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.

    The following notification appears at the top of the schema pane.

    Do you want to add the activity's parameters as input/output to the current workflow?

  4. On the notification, click Setup.

    A pop-up window with the available options appears.

  5. Select the mapping type for each input parameter.

    Option

    Description

    Input

    The argument is mapped to an input workflow parameter.

    Skip

    The argument is mapped to a NULL value.

    Value

    The argument is mapped to an attribute with a value that you can set from the Value column.

  6. Select the mapping type for each output parameter.

    Option

    Description

    Output

    The argument is mapped to an output workflow parameter.

    Skip

    The argument is mapped to a NULL value.

    Local variable

    The argument is mapped to an attribute.

  7. Click Promote.
  8. Right-click the Foreach element and select Synchronize > Synchronize presentation.

    A confirmation dialog box appears.

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

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

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

Results

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 defined.

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

Rename Virtual Machines by Using a Foreach Element

You can use a Foreach element to rename several virtual machines at once. You have to insert a Foreach element in a workflow and promote the vm and the newName parameters as input to the current workflow. 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 newName parameter.