VMware Cloud Community
mschubi
Enthusiast
Enthusiast

Foreach element with workflow that returns an array

Hi,

i have (may be) a trivial problem. I use the first time a orchestrator Foreach element in the context of running workflows which returns Arrays.

the Foreach workflow should collect all this returned Arrays to a new Array. but in the parameter binding it is not allowed to switch Array parameters to

iteration.

Am i beeing stubpid?

best regards,

Mike

0 Kudos
8 Replies
cdecanini_
VMware Employee
VMware Employee

You need to check the "Bind as iterator" checkbox when you click on the source parameter link.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
0 Kudos
mschubi
Enthusiast
Enthusiast

Hi Christophe,

thats my problem.

I have a parameter of type "Array". the "Bind as Iterator" button is grayed out...

best regards,

Mike

0 Kudos
cdecanini_
VMware Employee
VMware Employee

The goal of "for each" is to iterate each element of an array and pass it as parameter input of a workflow not taking an array for input.

For example you have an array of VM and want to run "Power On VM" workflow that takes a vm input.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
0 Kudos
mschubi
Enthusiast
Enthusiast

But how can i handle the Parmater that resturns the called Workflow.

I wrote a workflow that removes special snapshots of a given VM and returns the names of this

snapshots as an Array.

Now i wrote a workflows that should do this for some VMs. That all works fine. But i get in this workflow

only the returned Array of the last called Workflow in the foreach element. If it where only a parameter of may be "String",

than i can define that forech element put the single returned strings in to an array. so i get all return values of the iteration.

but at the moment it looks for me that orchestrator can't collect Array of Arrays.

best regards,

Mike

0 Kudos
cdecanini_
VMware Employee
VMware Employee

Maybe it would be more clear with a few screenshots.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
0 Kudos
mschubi
Enthusiast
Enthusiast

Hi Christophe,

thats a good idea.

I attached 3 screenshots.

the picture "vco_WF_Delete_Snaps_for_Single_VM_Params.PNG" views the Workflows Output Parameter.

This WF should be called in the foreach element.

The pictures "vco_WF_Delete_Snaps_for_VMs_IN-Param.PNG" and "vco_WF_Delete_Snaps_for_VMs_OUT-Param.PNG" shows the INPUT/OUTPUT bindings of the foreach element to call the WF for single VMs.

May be i am at the time a blockhead...

best regards,

Mike

0 Kudos
cdecanini_
VMware Employee
VMware Employee

So you use for each to get all the snapshots of all the VMs and you are willing to aggregate the arrays of the output ?

I do not think you can do such a binding for the output.

What you can do is to create a workflow that :

  • passes an array as input of the workflow
  • insert the workflow that output the array of snapshot, right click synchronize presentation to copy its inputs to the parent workflow, bind the output of this workflow to an attribute of the parent workflow.
  • use a scriptable box doing array.concat
  • output the aggregated array.

Such a workflow can be started in a foreach element with passing an empty array as input and should output the aggregated arrays.

There may be an easier solution.

You can also handle the loop yourself : http://www.vcoteam.info/learn-vco/creating-workflow-loops.html

I hope I got it right. If not apologies. I had a very long day.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
mschubi
Enthusiast
Enthusiast

Hi Christophe,

your idea ist good 🙂

Now it runs as i need this workflow.

In short for other readers.

I have a WF "A" that returns Array of Strings (lets say retArray). i wrote another WF "Wrapper_A" with input parameter "inArray" and and output parameter

"outArray". This WF calls the WF "A" and has an Script element (only outArray = inArray.concat(retArray)).

In the workflow that shoult be iterate over the WF "Wrapper_A" i initialze a attribute "allRetArray" with empty Array.

in the foreach element i bound input parameter and output parameter of "Wrapper_A" to this attribute.

So i get the returned Arrays of all called WF iterations.

I hope its possible to understand my bumpy english 😉

best regards,

Mike

0 Kudos