Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

What are Loop Actions?

 Loop 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  Start Loop Action  and an  End Loop Action, 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.

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  Loop icon from the toolbar onto the canvas
  2. In the Create Loop Action window:
    1. Enter a Name
    2. Select Create Action
  3. On the Start Loop action, 
  4. On the End Loop action



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

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.

 How?
  1. Create a new  Actionflow from the Actionflow home page
    1.  
    2. Name: Bank Holiday API
  2. In the toolbar, click  Properties
  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.  Apply your changes

Setup the Input Connection Point Input Parameters

  1. Click on the  input 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  JSON 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  input to the   JSON action 
  3. Map across the body attribute from the input

View Setup

  1. Create a   View 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   View action, add a filter:
    1. Name: SelectedYearOnly
    2. Filter Details: 
  5. Create an output connector between the   View action and the  output node
  6. Map across all attributes coming from the View to the output

Obtain the API URL

  1. Open the Actionflow  Properties and in the API section, copy the URL and save it locally to be used later
 Checkpoint

Actionflow Setup

This Actionflow will use a  Loop Action 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

Type Conversion

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

  1. Create a  Calculate 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

     How?

Create Loop Action

  1. Create a  Loop action
    1. Name: Loop Years
  2. Connect the  Calculate action to the  Start Loop Action
  3. Map across the YearFrom attribute

Create HTTP Action

  1. Create a  HTTP to call the Bank Holiday API
    1. Name: Call BH API
  2. Map across the YearFrom attribute from the  Start Loop Action to the HTTP action
  3. Rename the attribute on the HTTP action to CallingYear
  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: 

      [{
          "CallingYear": "${in.CallingYear}"
      }]
    4. Toggle on Log Traffic

       Checkpoint

Create JSON Action

  1. Create a  JSON 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

     How?

Save Action

  1. Create a  Save action to save the data
    1. Name: SaveBHs
    2. Type: Auto Insert/Update
    3. Table: click the  Table icon 
      1. Under Tables in the  Repository, click  to create a new table
        1. Name: Bank_Holiday_Results
        2. Add the attributes from the UK_Bank_Holidays table to this table
      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 
 Checkpoint


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  Calculate 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   Start Loop Action
    2.  
  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  Calculate action to the  End Loop Action
  2. Map across the LoopYear attribute from the Increment +1  Calculate action and the YearTo attribute from the ConvertToInteger  Calculate action
  3. Setup the  End Loop Action as follows:

  1. On the Loop connector between the  End Loop Action and  Start Loop Action map the LoopYear attribute to the YearFrom  attribute 


 Checkpoint


Testing

  1. Close all screens and reopen the 


3.05 Custom Confirmation Message Configuration

  • No labels