Insert excerpt | ||||||||
---|---|---|---|---|---|---|---|---|
|
Overview
Using lookups in Actionflows allows users to return multiple records as an array and has many applications, which is useful in a number of scenarios. This page covers the following:
Table of Contents |
---|
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 contains containing the following grid:
UID | Object | Colour |
---|---|---|
1001 | Table | White |
1002 | Chair | Black |
1003 | Computer | Silver |
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:
Code Block |
---|
UID [1001, 1002, 1003] Object ['Table', 'Chair', 'Computer'] Colour ['White', 'Black', 'Silver'] |
Note |
---|
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 to see which illustrate how lookups can be used effectively in an actionflow.:
Counting
selected recordsSelected Records
A user creates the above 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:
View file | |||
---|---|---|---|
|
|
- Drag and drop a button from the palette onto the button bar
- Name this Count Records
- Drag and drop a String Form Field onto the tile
- Name this RecordCount
- Right-click on the button and select Add actionflow
- Name the actionflow Count Records
Click Connect on the connections pane and select the Event input
Note 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.
Click Add on the connections pane
Name the connection CountRecords
Select Lookup
Click Create Connection Point
Select the Objects grid
- Click Connect Input
- On the mappings screen that appears drag the UID across to create a mapping.
- Make sure the data being used is set to Selected Records.
- Click Confirm Mappings Save
- Create a
Node by dragging and dropping from the toolbarInsert excerpt _actionflow_calculate _actionflow_calculate nopanel true - Name the node Count Records
- Connect the Event Input to the calculate. This is what causes the actionflow to run.
- Connect the Grid Lookup to the calculate
- Select Add Lookup
- Name the connection lu
- Drag and drop the UID field to create a mapping to the calculate.
- Click Confirm Mappings
- Click on the Calculate node to open its editor.
Add a calculate attribute:
Name: Count
Type: String
Order: 1
Expression:Code Block countElements(lu.UID) + " records"
- Save the attribute
Now we need to return the value back to the screen. To do this:
Click Add on the connections pane
Name the connection return
Select Output
Click Create Connection Point
Select the Objects form
- Click Connect Output
- Connect the calculate to the return output of the actionflow
- Hover over the calculate node
- Select Out
- Drop the arrow onto the return output to create the connection.
- Right-click on the connection between the calculate and return connection point and select Configure mappings
- Drag and drop the Count attribute from the calculate node to the return connection point.
- Right-click on on the connection between the return connection point and the Objects form.
- 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 Objects Object's table and wants to prevent duplicates from being added.
Note |
---|
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
Insert excerpt | ||||||
---|---|---|---|---|---|---|
|
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
- Add a new phase before the current phase
- Name the phase Duplicate Check
- Connect the Edit Form as an input into the actionflow
- Map in the Name and Colour attributes
- Create a
node by dragging and dropping from the toolbar.Insert excerpt _actionflow_calculate _actionflow_calculate nopanel true - Connect the interface to the calculate and map in Name and Colour.
- Hover over the calculate node and select Add Lookup
- Name the connection point dup
- Drop the arrow onto space in the canvas to create the
node.Insert excerpt _action_view _action_view nopanel true - Select the Objects table as the primary table
- Name the View Objects
- 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.
- Click Next
- 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.
- Click Next
- 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.
- Creating a filter. Click on the
node to open its editor. Under Data Retrieval Options clickInsert excerpt _action_view _action_view nopanel true
next to the Default Filter to add a filter. Provide the following informationInsert excerpt _add _add nopanel true - Name: Filter by Colour and Name
- Private: false
Select an option: Colour equals
Code Block req.Colour
Note req is used to reference the incoming attributes. Make sure to click the 'abc' button to convert it to an expression.
Click the add button to add a new condition
Select an option: Name equals
Code Block req.Name
- Click on the
node to open its editor and add a Calculate Attribute with the following settingsInsert excerpt _actionflow_calculate _actionflow_calculate nopanel true Name: DuplicateCheck
Type: Integer
Order: 1
Expression:Code Block 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.
Hover over the
and click Out.Insert excerpt _actionflow_calculate _actionflow_calculate nopanel true - Drag the arrow into empty space onto the actionflow and click where the new node should appear.
- Select
and select Processing Phase. This will then run the processing phase if the actionflow hasn't been stopped by the DuplicateCheck attribute.Insert excerpt _action_phase _action_phase nopanel true
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
Code Block |
---|
do( $count = countElements(dup.UID), if($count == 0, do( error("The colour provided is not valid"), stop() ), $count ) |
The
Insert excerpt | ||||||
---|---|---|---|---|---|---|
|
Note |
---|
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. |