Using Lookups in Actionflows

Overview

Using lookups in Actionflows allows users to return multiple records as an array, which is useful in a number of scenarios. This page covers the following:

Lookup connections

Lookup connections are represented by dotted lines in an actionflow. When called, they pass blocks of data as a single dataset (array) instead of passing each record one-by-one through the connection. Imagine a screen containing the following grid:

UIDObjectColour
1001TableWhite
1002ChairBlack
1003ComputerSilver

Actionflows can lookup to this data and retrieve all the records displayed on the grid by mapping to its attributes. This will then return all 3 records as an array in the format:

UID 	[1001, 1002, 1003]
Object	['Table', 'Chair', 'Computer']
Colour	['White', 'Black', 'Silver']

If the grid was wired into the actionflow using a driving connection, each record would pass into the actionflow one-by-one, and the actionflow would run 3 times.

Worked examples

See some worked examples below which illustrate how lookups can be used effectively in an actionflow:

Counting Selected Records

A user creates a grid on a screen: 

The user wants to create a button that counts the number of records that have been selected on the grid and display this in a form field. To do this:

  1. Drag and drop a button from the palette onto the button bar
  2. Name this Count Records
  3. Drag and drop a String Form Field onto the tile
  4. Name this RecordCount

  5. Right-click on the button and select Add actionflow
  6. Name the actionflow Count Records
  7. Click Connect on the connections pane and select the Event input

    All actionflows require an input to run. The event input must be connected as this will run the actionflow once. The actionflow is then wired to lookup the number of selected records.

  8. Click Add on the connections pane

    1. Name the connection CountRecords

    2. Select Lookup

    3. Click Create Connection Point

    4. Select the Objects grid

    5. Click Connect Input
  9. On the mappings screen that appears drag the UID across to create a mapping.
    1. Make sure the data being used is set to Selected Records.
    2. Click Save
  10. Create a  Calculate Node by dragging and dropping from the toolbar
    1. Name the node Count Records
  11. Connect the Event Input to the calculate. This is what causes the actionflow to run.
  12. Connect the Grid Lookup to the calculate
    1. Select Add Lookup
    2. Name the connection lu
    3. Drag and drop the UID field to create a mapping to the calculate.
    4. Click Confirm Mappings
  13. Click on the Calculate node to open its editor.
    1. Add a calculate attribute:
      Name: Count
      Type: String
      Order: 1
      Expression:

      countElements(lu.UID) + " records"
    2. Save the attribute

Now we need to return the value back to the screen. To do this:

  1. Click Add on the connections pane

    1. Name the connection return

    2. Select Output

    3. Click Create Connection Point

    4. Select the Objects form

    5. Click Connect Output
  2. Connect the calculate to the return output of the actionflow
    1. Hover over the calculate node
    2. Select Out
    3. Drop the arrow onto the return output to create the connection.
  3. Right-click on the connection between the calculate and return connection point and select Configure mappings
    1. Drag and drop the Count attribute from the calculate node to the return connection point.
  4. Right-click on the connection between the return connection point and the Objects form.
    1. Drag and drop the Count attribute onto the RecordCount string field to create a mapping.

The actionflow is now configured. Select records on the screen and try out the action.

Checking for duplicates

A user has an edit form for the Object's table and wants to prevent duplicates from being added.

To create an edit form right-click on the grid and select Add CRUD Actions. Follow the steps and PhixFlow will guide you, in creating the add, edit and delete actions to update the data.

The preconfigured save action connects the form to the actionflow and maps in the primary key. The primary key is then mapped to a  Save node which inserts the new record.

The easiest way to add a check for duplicates is to add a new phase before the current processing phase. To learn more about phases, see Using Actionflow Phases.

To check for duplicates

  1. Add a new phase before the current phase
  2. Name the phase Duplicate Check
  3. Connect the Edit Form as an input into the actionflow
  4. Map in the Name and Colour attributes
  5. Create a  Calculate node by dragging and dropping from the toolbar.
  6. Connect the interface to the calculate and map in Name and Colour.
  7. Hover over the calculate node and select Add Lookup
  8. Name the connection point dup
  9. Drop the arrow onto space in the canvas to create the  View node.
    1. Select the Objects table as the primary table
    2. Name the View Objects
  10. An output attribute selection popup should appear. Add attributes to the view node by selecting all the attributes and dragging and dropping them onto the Output Attributes section on the View property editor.
    1. Click Next
    2. Incoming Mappings. In this example, Incoming Mappings are required to filter the records in the Object table by the colour and name attributes. Drag and drop the attributes Name and Colour to the Objects view node to create a mapping. This will be used to configure the filter later.
    3. Click Next
    4. Outgoing Mappings. An attribute is required to be used to map back to the calculate node. Drag and drop UID from the view to the calculate node. This will be used in the calculate attribute expression later.
  11. Creating a filter. Click on the   View node to open its editor. Under Data Retrieval Options click  Add New next to the Default Filter to add a filter. Provide the following information
    1. Name: Filter by Colour and Name
    2. Private: false
    3. Select an option: Colour equals 

      req.Colour

      req is used to reference the incoming attributes. Make sure to click the 'abc' button to convert it to an expression.

    4.  Click the add button to add a new condition

    5. Select an option: Name equals

      req.Name
  12. Click on the  Calculate node to open its editor and add a Calculate Attribute with the following settings
    1. Name: DuplicateCheck
      Type: Integer
      Order: 1
      Expression:

      do(
      	$count = countElements(dup.UID),
      	if($count > 0,
      		do(
      			error("There is already an Object with the name" + in.Name + "and colour " + in.Colour),
      			stop()
      	),
      	$count
      )

      This will display a user error and stop the actionflow immediately if any duplicates are found.

  13. Hover over the  Calculate and click Out.

    1. Drag the arrow into empty space onto the actionflow and click where the new node should appear.
    2. Select  Phase and select Processing Phase. This will then run the processing phase if the actionflow hasn't been stopped by the DuplicateCheck attribute.

Checking a value is in a list

To configure an actionflow to check if a value is in the list follow the steps for Checking for Duplicates. Instead of checking for duplicates and stopping the actionflow if a duplicate is found, the logic in the Calculate Attribute expression needs to be reversed. The logic should be something like

do(
	$count = countElements(dup.UID),
	if($count == 0,
		do(
			error("The colour provided is not valid"),
			stop()
	),
	$count
)

The   View node in the actionflow can be backed by any table of data. For example, a Colour table could be used which contains all the valid colours. The actionflow can then check that the colour provided by the user is in the list of valid colours and error if it is not found. This prevents users adding inconsistent data.

A better way to prevent inconsistent data being added via an edit form is to use drop downs. If the data isn't being entered by a user then this method is the best way to check the incoming values.