Versions Compared

Key

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

Insert excerpt
_Banners
_Banners
nameactionflow
nopaneltrue

What

is a

are Loop

Action

Actions?

Image RemovedImage Added

Click the 

The 

Insert excerpt
_action_bulkupdateloop
_action_bulkupdateloop
nameloop
nopaneltrue
 action updates re

Creating Bulk Update Actions

 actions repeat an action or set of actions multiple times. 

In PhixFlow, there are three types of supported looping:

Polling

Repeats the same operation multiple times with the same parameters, until a desired result is obtained.

  • Generates a single output record
    • Output results are only generated at the end of the iterations
  • Example: polling a HTTP API until the results are available

Accumulation

Repeats the same operation multiple times, where each iteration accumulates the progress results and triggers the next iteration with the updated result.

  • Generates a single output record
  • Example: calling a database (DB) to get a parent record, and then repeating the call with the parent until the root has been reached

Paging

Repeats an operation multiple times with different parameters.

  • Generates the next parameters with a set of output records for each iteration of the loop
  • Example: reading from a paging API, where each iteration provides the link for the next iteration and a set of output records

Start Loop and End Loop

Loops consist of a

Insert excerpt
_action_

bulkupdate

loop_start
_action_

bulkupdate

loop_start
nopaneltrue

 icon in the toolbar to display any existing tables in the applicationExisting tables can be dragged from the Repository onto the canvas, then choose 

  and an 

Insert excerpt
_action_

bulkupdate

loop_end
_action_

bulkupdate

loop_end
nopaneltrue

 to create a Bulk Update nodeAlternatively,

,joined by a loop connector which returns the result of the End node to the Start node. Each part of the Loop has its own set of properties described below.

The key concept of a loop is that the attributes passed into it are available as passthrough, as well as attributes mapped in from the End Loop. This allows the original passthrough values to be referenced and if the loop is manipulating the incoming attributes, for example, incrementing a number, this is also available. The mapped attributes that are manipulated by the loop are shown with a loop icon, passthrough attributes will be shown with the icon of where they have come from, for example a calculated action.

Tip

Loops wait until all their internal nodes have completed their tasks before beginning the next iteration of a loop.

Creating Loop Actions

  1. Click and drag the 
    Insert excerpt
    _action_
    bulkupdate
    loop
    _action_
    bulkupdate
    loop
    nameloop
    nopaneltrue
     icon from the toolbar onto the canvas
  2. In the Create Bulk Update ActionLoop Action window:
    1. Enter a NameChoose to Allow Audited Table to display tables with Audit Manual Changes enabled in the Table drop downBy default, tables with Audit Manual Changes enabled are not shown in the Table drop down list
    2. Choose the Table from the drop down where the records will be updated
      1. Or click the table icon to display tables in the Repository
    3. Select Create Action
When creating update actions it can be useful to set up confirmation messages that allow users to confirm or cancel the update. See 1.13 Confirmation Message Configuration.
  1. On the Start Loop action, 
  2. On the End Loop action


HTML Comment
hiddentrue



Worked Example

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

In this example, we are using:  

  • Company Management screen containing a grid of the Companies data and a card container of their associated Employees - this screen was created using the Multi-Tile template
  • Company Merger Pop up screen containing:
    • 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 Tile no Buttons template
  • Company Orders screen containing two grids of the Orders and OrderLines data - this screen was created using the Multi-Tile 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 Management screen.

Bulk Update Employees and Orders for Company Acquisition

In this example, a company is being merged into another company and we need to update the employees and orders to reflect the change.

GIF

Create API End Point Actionflow

In this example, we'll set up an Actionflow that will act as an UK Bank Holiday API that can be called by another Actionflow. This Actionflow will be configured to receive a year parameter and use that parameter to pass out the bank holiday dates for the corresponding year. If you have completed the worked example on 3.01 Setting up an API End Point, the setup is very similar.

Expand
titleHow?
  1. Create a new
    Insert excerpt
    _actionflow
    _actionflow
    nopaneltrue
     from the Actionflow home page
    1. Image Added 
    2. Name: Bank Holiday API
  2. In the toolbar, click 
    Insert excerpt
    _property_settings
    _property_settings
    nopaneltrue
  3. In the API section of the properties, enable API End-Point
  4. This allows the Actionflow to receive an incoming API
  5. Enable Allow Anonymous Connections
  6. Insert excerpt
    _save
    _save
    nopaneltrue
     your changes

Setup

  1. Open the Company Management screen
  2. Click the Merge button to open the Company Merger Pop up screen
  3. Create an Actionflow on the Run Acquisition button
    1. Name: RunCompanyAcquisition
  4. On the Actionflow canvas,
Expand
titleCheckpoint

Testing

  • Close all screens and reopen the Company Management screen
  • Choose two companies to merge and make a note of their employees so you can see if the merge is successful
  • Open the Company Orders screen and make a note of any Orders and Order Lines for the two companies
  • On the Company Management screen, click the Merge button to open the Company Merger Pop up screen
  • Select the two companies to merge and click the Run Acquisition button
  • Review the screens to check the merge was successful

    the Input Connection Point Input Parameters

    1. Click on the
      Insert excerpt
      _input
      _input
      nopaneltrue
       Connection Point
    2. In the Properties that open, in the Input Parameters section, add the following attributes (the names are case sensitive):
    NameTypeDescription
    bodyStringprovides the information sent in the body of the API call.
    contentTypeStringProvides details of the Content Type
    headersStringProvides the information sent in the API call header.
    urlStringProvides the complete URL that was used to call the API. This can be used to pass parameters to the API.  

    JSON Setup

    1. Create a 
      Insert excerpt
      _action_json
      _action_json
      nopaneltrue
       action to receive the parameter
      1. Name: ReceiveYear
      2. Input Expression: in.body
      3. Path: $
      4. Create an Output Attribute on the JSON action
        1. Name: YearReceived
        2. Type: String
        3. Expression: _result.Year
    2. Connect the 
      Insert excerpt
      _input
      _input
      nopaneltrue
       to the  
      Insert excerpt
      _action_json
      _action_json
      nopaneltrue
       action 
    3. Map across the body attribute from the input

    View Setup

    1. Create a
      Insert excerpt
      _action_view
      _action_view
      nopaneltrue
       action for the UK_Bank_Holidays table
    2. Configure the Output Attributes that the API should return
      1. UID
      2. Name
      3. Date
      4. Country
    3. Connect the JSON action to the View action and map across the YearReceived attribute
    4. On the 
      Insert excerpt
      _action_view
      _action_view
      nopaneltrue
       action, add a filter:
      1. Name: SelectedYearOnly
      2. Filter Details: Image Added
    5. Create an output connector between the 
      Insert excerpt
      _action_view
      _action_view
      nopaneltrue
       action and the 
      Insert excerpt
      _output
      _output
      nopaneltrue
       node
    6. Map across all attributes coming from the View to the output

    Obtain the API URL

    1. Open the Actionflow
      Insert excerpt
      _property_settings
      _property_settings
      nopaneltrue
       
      and in the API section, copy the URL and save it locally to be used later


    Expand
    titleCheckpoint

    Image Added

    Actionflow Setup

    This Actionflow will use a

    Insert excerpt
    _action_loop
    _action_loop
    nameaction
    nopaneltrue
     to poll the API setup above to retrieve the bank holidays for the years selected on the Company Bank Holidays API - Loops screen.

    1. Open the Company Bank Holidays API - Loops screen
    2. Add an Actionflow to the Run button
      1. Name: Get Bank Holidays
    3. Choose the input of the CompanyBankHolidayAPI-Loops form
    4. Map in the two input fields:
      1. YearFrom
      2. YearTo
    5. On the Mappings window, change the names of these two attributes to:
      1. YearFromIn
      2. YearToIn
        1. Image Added

    Type Conversion

    The data coming into the Actionflow is in the Type, String. Our Actionflow needs this data in Integer format.

    1. Create a 
      Insert excerpt
      _action_calculate
      _action_calculate
      nopaneltrue
       action
      1. Name: ConvertToInteger
    2. Map both attribvutes from the input to the Calculate action
    3. Use the function toNumber to create two Output Attributes on the Calculate action that convert the strings to integers

      Expand
      titleHow?

      Image Added


    Create Loop Action

    1. Create a 
      Insert excerpt
      _action_loop
      _action_loop
      nameloop
      nopaneltrue
       action
      1. Name: Loop Years
    2. Connect the 
      Insert excerpt
      _action_calculate
      _action_calculate
      nopaneltrue
       action to the 
      Insert excerpt
      _action_loop_start
      _action_loop_start
      nopaneltrue
    3. Map across the YearFrom attribute

    Create HTTP Action

    1. Create a 
      Insert excerpt
      _action_http
      _action_http
      nopaneltrue
       to call the Bank Holiday API
      1. Name: Call BH API
    2. Map across the YearFrom attribute from the 
      Insert excerpt
      _action_loop_start
      _action_loop_start
      nopaneltrue
       to the HTTP action
    3. Rename the attribute on the HTTP action to CallingYear
      1. Image Added
    4. In the HTTP Action properties, enter the following:
      1. HTTP Method: POST
      2. URL: Paste in the URL you copied earlier and saved locally
      3. Body: 

        Code Block
        themeEmacs
        [{
            "CallingYear": "${in.CallingYear}"
        }]


      4. Toggle on Log Traffic

        Expand
        titleCheckpoint

        Image Added


    Create JSON Action

    1. Create a 
      Insert excerpt
      _action_json
      _action_json
      nopaneltrue
       to process the returned bank holiday data from the API
      1. Name: Returned Bank Holidays
    2. Connect the HTTP action to the JSON action
    3. Map across the body from the HTTP action
    4. Setup the JSON action to receive the data from the API

      Expand
      titleHow?

      Image Added


    Save Action

    1. Create a 
      Insert excerpt
      _action_save
      _action_save
      nopaneltrue
       action to save the data
      1. Name: SaveBHs
      2. Type: Auto Insert/Update
      3. Table: click the 
        Insert excerpt
        _tables
        _tables
        nopaneltrue
         icon 
        1. Under Tables in the 
          Insert excerpt
          _repository
          _repository
          nopaneltrue
          , click 
          Insert excerpt
          _add_icon
          _add_icon
          nopaneltrue
           to create a new table
          1. Name: Bank_Holiday_Results
          2. Add the attributes from the UK_Bank_Holidays table to this table
          3. Image Added
        2. Select this table on the Create Save Action drop down
        3. Click Create Action
    2. Connect the JSON action to the Save action and map across the attributes being returned by the JSON action 
      1. Image Added
    Expand
    titleCheckpoint

    Image Added


    Increment Year By One

    After the bank holiday data has been saved, we need the loop to go round again, this time getting the next year in the sequence, for example, if the user has entered 2018 for the YearFrom and 2020 for the YearTo, when the data first hits the Save action, it is just the 2018 data. For the second loop, the 2019 data will be obtained.

    1. Create a 
      Insert excerpt
      _action_calculate
      _action_calculate
      nopaneltrue
       action
      1. Name: Increment +1
    2. Connect it to the Save action and map across the YearFrom attribute
      1. Ensure this is the attribute from the  
        Insert excerpt
        _action_loop_start
        _action_loop_start
        nopaneltrue
      2. Image Added 
    3. On the Calculate action, add an Output Attribute:
      1. Name: LoopYear
      2. Type: Integer
      3. Expression: in.YearFrom + 1

    End Loop Setup

    1. Connect the Increment +1 
      Insert excerpt
      _action_calculate
      _action_calculate
      nopaneltrue
       action to the 
      Insert excerpt
      _action_loop_end
      _action_loop_end
      nopaneltrue
    2. Map across the LoopYear attribute from the Increment +1 
      Insert excerpt
      _action_calculate
      _action_calculate
      nopaneltrue
       action and the YearTo attribute from the ConvertToInteger 
      Insert excerpt
      _action_calculate
      _action_calculate
      nopaneltrue
       action
      1. Image Added
    3. Setup the 
      Insert excerpt
      _action_loop_end
      _action_loop_end
      nopaneltrue
       as follows:

      1. Image Added
    1. On the Loop connector between the 
      Insert excerpt
      _action_loop_end
      _action_loop_end
      nopaneltrue
       and 
      Insert excerpt
      _action_loop_start
      _action_loop_start
      nopaneltrue
       map the LoopYear attribute to the YearFrom  attribute 
      1. Image Added


    Expand
    titleCheckpoint

    Image Added


    Testing

    1. Close all screens and reopen the 


    3.05 Custom Confirmation Message Configuration