VMware Cloud Community
lurims
Enthusiast
Enthusiast

ForEach Workflow iterator error handling

I like the workflow iterator ForEach to run a workflow for a number of times.  But how do catch up to all errors occur (say for example I am renamig 10 VMs name, 3 of them failed).  Currently it is showing only the last error, previous errors are overwritten.  Could someone show an example on how to collect all errors and fail at the end?

0 Kudos
1 Reply
iiliev
VMware Employee
VMware Employee

Hi,

Let's assume that the workflow being iterated on (in your case, the workflow that renames a VM) detects the error during renaming and returns it in a workflow output parameter.

Then in the workflow where you do the iterations using ForEach element, you can do the following:

  • add a workflow attribute of type Array/string and give it an empty array value; the errors will be collected into this attribute
  • select the ForEach element, and on its OUT tab bind the 'Accumulate workflow outputs in' to this attribute
  • after the ForEach element, insert a Scriptable task element, and on its IN tab select the same attribute
  • on the same Scriptable task Scripting tab, add some code that will examine the content of the attribute, and will fail the workflow if certain conditions are met, ie. if the attribute where the errors are collected contains at least one element, or if the collected errors contain some specific message, etc.

Hope the above makes sense.

0 Kudos