Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Insert excerpt
_Banners
_Banners
nameactionflow
nopaneltrue

What is a For Each Action?

Security can b 

Image Added

The 

Insert excerpt
_action_foreach
_action_foreach
nopaneltrue
 action iterates over a set of records or list of values, and generates an output record for each one. It is most commonly used to split data, such as an array, into individual records, or it can be used in conjunction with a 
Insert excerpt
_action_calculate
_action_calculate
nopaneltrue
 action to firstly convert a user-inputted list into an array for the 
Insert excerpt
_action_for_each
_action_for_each
nopaneltrue
 action to process - see worked example below.   

Creating For Each Actions

  1. Click and drag the 
    Insert excerpt
    _action_foreach
    _action_foreach
    nopaneltrue
     
    icon from the toolbar onto the canvas
  2. Enter a name in the Create For Each Action window and select Create Action
  3. In the 
    Insert excerpt
    _action_foreach
    _action_foreach
    nopaneltrue
     action 
    Insert excerpt
    _property_settings
    _property_settings
    nopaneltrue
     
    on the right, populate the following:
FieldDescriptionExample Value
Input Expression

The input expression provides the source of the data to be iterated over. Typically, this will be a simple expression pointing at an Input Attribute, using the syntax, Connector.AttributeName.

If an empty record set or empty list is provided then no output will be generated.

This field is mandatory (PhixFlow version 11.1 +).

// Receives a list of Invoice IDs, these are iterated over using

in.InvoiceID     

Input Attributes

Attributes mapped into the For Each action will appear here. 

If adding a new input attribute, a Name and Type are required. See Understanding Data Types.


Output Attributes

Attributes mapped out of the For Each action will appear here.

If adding a new output attribute, a Name, Type and Expression are required. This is a PhixScript expression. Values returned by the Input Expression are available in this expression as:

_result.value

To work in a larger popup window, click 

Insert excerpt
_editor_expand
_editor_expand
nopaneltrue
.

See also:

Name: Invoices

Type: String 

Expression: _result.value


HTML Comment
hiddentrue

Insert excerpt
For Each Node
For Each Node
namepage
nopaneltrue

Worked Example

Here's a worked example using the Company Data (available from the Learning Centre).

In this example, we are using:  

  • A Company Merger Pop upFor Each Example screen containing:
    • an input String Field two manual drop down fields of the company name's of the companies to be merged
    • two string fields showing the company ID's of the companies to be merged
    • a button to initiate the Actionflow - this screen was created using the Multi-Tile no Buttons template
Tip

If you are completing this chapter as part of the Actionflow course and using a training instance, the data and screens have already been pre-loaded into the Actionflow Advanced Application. For this example, we'll be working on the Company Merger Pop up screen.

Limit Permission to Merge Companies

Split a List Into Individual Records

In this example, we'll limit the users/user groups that can run the Actionflow that merges two companies togethertake a list of values inputted by a user and convert these into individual records.

gif

Prerequisites

Actionflow Setup

For this example, we'll limit permission to run an Actionflow that merges two companies together. This Actionflow was created in 3.04 Bulk Update Action Configuration. If you have not completed this chapter, expand the section below and follow the steps to create the Actionflows.

Expand
titleBulk Update Company Acquisition Actionflow
Insert excerpt3.04 Bulk Update Action Configuration3.04 Bulk Update Action ConfigurationnameBulkUpdateExamplenopaneltrue

Create Limited Access User

In the  Insert excerpt_repository_repositorynamefullnopaneltrue, ex

Testing

  1. Log out and login as the user Limited AccessClick the Run Acquisition buttonOpen the Company For Each Example screen
  2. Add an
    Insert excerpt
    _actionflow
    _actionflow
    nopaneltrue
     to the Save button
  3. Configure the Input as the CompanyForEachExample form
  4. Map the attribute Text into the Actionflow

Calculate Action - Convert List to Array

Use the split function in a 

Insert excerpt
_action_calculate
_action_calculate
nopaneltrue
 action to split the Text attribute by the comma separator. This will convert the list entered by the user into an array.

Expand
titleHow?
  1. Create a 
    Insert excerpt
    _action_calculate
    _action_calculate
    nopaneltrue
     action
  2. Connect the 
    Insert excerpt
    _input
    _input
    nopaneltrue
     to the Calculate action
    1. Map across the Text attribute
  3. In the Calculate action, create an Output Attribute:
    1. Name: Split
    2. Type: Structured Data
    3. Expression: split(in.Text,",")


Expand
titleCheckpoint

Image Added

Calculate Action - Create Session ID (Optional)

Create a SessionID attribute in a 

Insert excerpt
_action_calculate
_action_calculate
nopaneltrue
 action to allow identification of records created at the same time, which we will use for filtering.

Expand
titleHow?
  1. In the Calculate action, create another Output Attribute:
    1. Name: SessionID
    2. Type: String
    3. Expression: now() + _user.username
  2. Insert excerpt
    _finish
    _finish
    nopaneltrue


Expand
titleCheckpoint

Image Added

For Each Action - Convert Array to Records

Use a 

Insert excerpt
_action_for_each
_action_for_each
nopaneltrue
 action to convert the array into individual records.

  1. Create a 
    Insert excerpt
    _action_for_each
    _action_for_each
    nopaneltrue
     action 
    1. Name: Convert to Records
  2. Connect it to the Calculate action and map across the Split attribute
  3. On the For Each action, enter the following:
    1. Input Expression: in.Split
    2. Input Attributes: Split
    3. Create two Output Attributes: 
      1. Name: Name
        1. Type: String
        2. Expression: trim(_result.value)
          1. The trim function is used here to remove the whitespace after the comma separator in the list
          2. If this was not used and the list "one, two, three" was entered, the records "two" and "three" would be saved with prefixed whitespace
      2. Name: LastUpdated
        1. Type: Datetime
        2. Expression: now()
  4. Insert excerpt
    _finish
    _finish
    nopaneltrue
Expand
titleCheckpoint
Image Added

Create a Sequence Number for UID (Optional)

Create a Sequence in your application to give each record a unique value. Alternatively, the UID attribute can be left unmapped and PhixFlow will automatically create a unique identifier.

  1. Open the 
    Insert excerpt
    _repository
    _repository
    nopaneltrue
     for your application
  2. Expand the 
    Insert excerpt
    _sequences
    _sequences
    nopaneltrue
     option, then click 
    Insert excerpt
    _add_icon
    _add_icon
    nopaneltrue
    1. Name: Unique_ID
    2. Start Value: 1
    3. Block Size: 1
  3. Insert excerpt
    _finish
    _finish
    nopaneltrue

Image Added

Add the Sequence Number to the UID Attribute (Optional)

Create an Output Attribute, UID, on the

Insert excerpt
_action_for_each
_action_for_each
nopaneltrue
 action using the Sequence you created above. 

Expand
titleHow?
  1. On the For Each action, create an Output Attribute: 
    1. Name: UID
      1. Type: Integer
      2. Expression: nextValue('Unique_ID')
  2. Insert excerpt
    _finish
    _finish
    nopaneltrue


Expand
titleCheckpoint

Image Added

Save Action 

Use a 

Insert excerpt
_action_save
_action_save
nopaneltrue
 to save the data to the ForEachExample table.

Expand
titleHow?
  1. Create a 
    Insert excerpt
    _action_save
    _action_save
    nopaneltrue
     action for the ForEachExample table
  2. Connect it to the For Each action
  3. Map across all attributes from the For Each action
  4. Map across the SessionID attribute from the Calculate action, if created
  5. In the Save action 
    Insert excerpt
    _property_settings
    _property_settings
    nopaneltrue
    , change the Type to Insert

Image Added

Output - Map SessionID Onto Screen (Optional) 

If you have created a SessionID attribute, an output will need to be created to map this value onto the SessionID String Field on the screen, so that it can be used for filtering.

Expand
titleHow?
  1. Under Connections, create an output connection point to the CompanyForEachExample form
  2. Hover over the Save action and click, out, then select the 
    Insert excerpt
    _output
    _output
    nopaneltrue
     node
  3. Map across the SessionID attribute from the table (not the Calculate action) to the output
  4. Click on the output connector under Connections and map the SessionID attribute from the output to the screen


Expand
titleCheckpoint

Image Added

Testing


Image Modified