How to - FOREACH WF setup using array
search cancel

How to - FOREACH WF setup using array

book

Article ID: 206224

calendar_today

Updated On:

Products

CA eHealth CA Automic Workload Automation - Automation Engine

Issue/Introduction

This article will explain how to setup a FOREACH workflow that uses an array instead of a variable object to pass values down to the FOREACH workflow properties.  This is just one example; the Broadcom Automic community may be a good place to get more information.

The functions and objects used in this article:
:PUBLISH - https://docs.automic.com/documentation/webhelp/english/AA/12.3/DOCU/12.3/Automic%20Automation%20Guides/help.htm#Script/Reference/PUBLISH.htm
FOREACH Workflows - https://docs.automic.com/documentation/webhelp/english/AA/12.3/DOCU/12.3/Automic%20Automation%20Guides/help.htm#AWA/Workflows/wf_PropertiesPane_ForEach.htm

Environment

Release : 12.3

Component : AUTOMATION ENGINE

Resolution

One way to do this is the following:

1) Create a Workflow (here, called WF.PARENT) which is the workflow (WF) that will be at the top of everything
2) Create a Script object (or JOB), here called SCRI.CREATE.ARRAY
3) Add the following to the Process tab - this creates the array and publishes (pushes them up to the parent) that array and values:

!Define an array with 3 entries
:DEFINE &ARR#, unsigned, 3
!set the 3 entries to values
:SET &ARR#[1] = 20
:SET &ARR#[2] = 30
:SET &ARR#[3] = 40
!publish the array (push up to parent)
:PUBLISH &ARR#[]

4) Create a Foreach or FE workflow - here called JOBP.FE_ARRAY
5) Click on the "Start" node and go to Properties, and go to the For Each button
6) Choose the radio button "PromtSet/Script array"

under Name, put in ARR[] (this is the name of the array from step 3 and it's necessary that there is no "&" at the beginning)
under "Publish Value as", put a variable name that will be used in the child objects - here this is called &TEST#

7) Create a task that can go in the FE workflow, here called "SCRI.PRINT_ARRAY_VALUES", and consume the array value &TEST# in some, for example with a simple:

:PRINT &TEST#

8) In the top parent workflow, WF.PARENT, place the script object from step 2, SCRI.CREATE.ARRAY into the first task spot and put the Foreach Workflow, JOBP.FE_ARRAY into the second task spot
9) In the child workflow, JOBP.FE_ARRAY, put in the script from step 7, SCRI.PRINT_ARRAY_VALUES.

Running the top workflow, WF.PARENT will create the array in SCRI.CREATE.ARRAY and publish it up to WF.PARENT so that all subsequent tasks inherit that array, then JOBP.FE_ARRAY will run SCRI.PRINT_ARRAY_VALUES for each entry in the ARR[] array, passing each array positions value as the object variable &TEST# and print this to the task report.