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

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 must select the output parameters of the Foreach element in which to accumulate workflow outputs, so that the subworkflow can iterate over them as well.

Procedure

  1. Log in to the vRealize Orchestrator Client.
  2. Navigate to Library > Workflows, and select your workflow.
  3. In the workflow editor, select the Schema tab.
  4. From the Generic menu, drag a Foreach element in the workflow schema.
  5. Create variables for the items in the array.
  6. Under Workflow, select the workflow you want to add to the Foreach element.
    The input and output parameters of the selected workflow are added to the Foreach element.
  7. Add an iteration error handler.
  8. Add a variable you want to use for exception handling.

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 variables that you have defined.

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

Example: 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.