For Each Collection Element Example Flow Chart

For Each Collection Element Example Flow Chart

A For Each Collection Element Action iterates through a collection of data that you specify. The collections supported include Java Arrays, Lists, Maps, and Sets.

Each time control of the flow chart passes through the For Each Collection Element Action, it will collect information about the next element in the collection. This information is returned through the flow context. Successive triggers and actions can access this data, using it to perform operations or to decide which action should be taken next.

This example will show you how to set up a For Each Collection Element Action with an Array of Strings, then use runtime data mapping to display each String using a Console Action. Following this example, you will learn to set up a For Each Collection Element Action, iterate through the elements in a collection, and how to access and use the returned data.

Getting Started

The Flux Designer will be used to create and execute the example flow chart. Start the Designer by executing the flux-designer script from the Flux installation directory.


Once the Designer is running, select "File" -> "Open Project". Browse to the /examples/end_users/for_each_collection directory and select the file fluxproject.fpr, then click "Open" to load the example project.

If you need a reference while creating the example (or if you simply want to see it in action), this project includes a complete, pre-constructed version of the example flow chart. To view the flow chart, locate the "Project View" panel to the left of the Designer workspace, then double-click the "For Each Collection Element" flow chart. Proceed to the section "Running The Flow Chart" for instructions on executing the example.

If you would rather create the example flow chart yourself, select "File" -> "New". Click the "New Flow Chart" option in the window that appears, then click "OK".

Creating a New Flow Chart in the Flux Designer

Name the new flow chart For Each Collection Element, then click the "OK" button.

Creating Actions

When you return to the Designer, you will see a blank workspace representing the new flow chart. To create the example, you will need to populate the new flow chart with a few actions.

To add an action to the flow chart, select the appropriate category from the "Actions & Triggers" panel located to the left of the Designer workspace.

The Actions and Triggers Panel

When you have located the action you want to add, drag it from the Actions & Triggers panel to the Designer workspace.

The lists below contain the name of each trigger and action you will need for this example, the required quantities, and the category each is located under in the Actions & Triggers panel.

“Actions” Tab:

  • Action: “For Each Collection Element Action”
    • Category: “Core”
    • Quantity: 1
  • Action: “Console Action”
    • Category: “Core”
    • Quantity: 1

When you have added the necessary actions to the new flow chart, arrange them according to (cross reference) below:

The Actions Used in This Example

Setting up Flows

Using (cross reference) below as a guide, create flows between the actions. To create a flow:

  1. Click somewhere within the blank white space on the Designer workspace.
  2. Click and hold the left mouse button on the action you wish to draw the flow from.
  3. Drag your cursor to the action you wish to draw the flow to and release.

The Example Flow Layout

Editing the Action Properties

Before you can run the flow chart, you will need to set up the actions with a few simple properties. Following these instructions, you will:

  1. Create a new collection for the For Each Collection Element Action to iterate over.
  2. Create a runtime data map to transfer information between the two actions.
  3. Give the Console Action a simple message to display.

For Each Collection Element Action

Click the For Each Collection Element Action in the Designer workspace. The “Action Properties” panel will appear to the right of the workspace.

For Each Collection Element Action's Action Properties

Locate the “Collection” property and select it. Click the "..." button to the right of the field and the "Arguments Editor" window will appear.

Arguments Editor

Click the "+" button to add a new collection.

The Add Variable Window

Select "Array" from the "Type" menu, then click "OK" to create the collection. Your “Arguments Editor” window will now look like this:

The Arguments Editor with a Newly Added Array

Now you can begin adding entries into the Array. To add an entry, click the field labelled "0 entries", then right-click the field while it is still selected.

Adding a New Entry

Click “Add New Entry”. The following window will open:

Adding an Element to the Collection

Select "String" from the "Type" menu and click "OK" to add a new String to the Array.

To view this addition, click the small icon to the left of the Array in the "Arguments Editor" window.

Viewing the Elements of a Collection

Edit the String by clicking within the blank text field to the right of the element’s number. Enter John in the text field.

Editing the Collection Element

Following the same procedure, add two more String elements to the Array. Edit these elements to read Jane and James. When finished, your “Arguments Editor” will look like this:

The Complete Collection of Strings

Once all three Strings have been added, click the "OK" button to close the editor. You will return to the Designer workspace. Check the For Each Element Action's "Collection" property in the "Action Properties" panel to ensure that the Array was added correctly.

Next, make sure that the "Start Action" property is set to "true". This will ensure that the For Each Collection Element Action is the first action that the flow chart executes.

Also notice that the "Loop Index" is set to "i" by default. This variable contains the collection element that is being iterated over, and is returned through the flow context each time the For Each Collection Element Action executes. In this example, the variable will be used to set up the Console Action.

Console Action

The Console Action in this example will simply be used to print out the String returned on each iteration of the For Each Collection Element Action.

To implement this, open the Console Action's "Action Properties". Select the "Runtime Data Map" property and click the "..." button.

Console Action's Action Properties

The "Edit Runtime Data Map" window will appear. Click the "+" button to add a new runtime data map: 
Adding a New Runtime Data Map

When the new runtime data map appears, double-click the blank text field under the left-most "Name" heading. Edit the field to read i, which is the For Each Collection Element Action's "Loop Index". See the screenshot below for reference: 
Editing the Runtime Data Map

Now, click somewhere within the right-most "Name" field and select "Message" from the menu, as in the following screenshot: 
Select the Message Property

Mapping the "Loop Index" property of the For Each Collection Element Action to the Console Action's "Message" property allows the Console Action to print whatever information is returned from the For Each Collection Element Action.

After you have set up the runtime data map, make sure that the Console Action's "Start Action" property is set to false.

Your flow chart is now complete! When the flow chart is executed, the For Each Collection Element Action will pass information through the flow context about the first element of the collection, "John". The Console Action prints the name, then loops back to the For Each Collection Element Action. This process is repeated until all elements of the collection are exhausted.

Creating a Flux Engine

Run the start-unsecured-flux-engine script from the Flux installation directory to start a new engine.

When the engine is up and running, return to the Flux Designer and hover your cursor over the "Flux Engines" tab, located on the left-hand side of the Designer window.

The Engines Tab

Click the "+" button to launch the Engine setup wizard.

The Flux Designer Engine Setup Wizard

Click on the “Advanced” tab at the top of the window, then click the "OK" button. When you arrive back at the Designer workspace, look at the “Flux Engines” tab again. The engine you just started will appear.

The Running Engine Indicator

Running the Flow Chart

Execute your flow by exporting it to the running engine. To do so, simply right-click within the white space anywhere on the Designer workspace and select "Export to Remote Flux Engine" from the menu.

Exporting to the Engine From the Designer Workspace

Click "OK" in the window that appears.

Select an Engine for Exporting

A confirmation window will appear if the job was successfully exported. If you receive an error message, carefully review the example and make any necessary corrections.


Flow Chart Successfully Exported

Once this example is completed, shut down your engine by running the shut-down-unsecured-flux-engine script from the Flux installation directory.

Was this article helpful?
0 out of 0 found this helpful



Please sign in to leave a comment.