Insert excerpt | ||||||||
---|---|---|---|---|---|---|---|---|
|
What is a For Each Action?
The
Drag Types and Drop Targets
Using drag and drop in an application allows users to click and drag an item from location to another within the user interface (UI). This feature is an intuiative way for users to interact with content, rearrange items, and trigger actions by dropping the oitems onto a designated area. enahnce user experience and make the application more engaging and easier to use.
In a PhixFlow application, you can configure drag-and-drop actions using actionflows and table actions. Some examples of drag and drop actions are:
- Dragging a record from a grid onto a delete area to remove it.
- Dragging a contact from one grid onto a specific company on a company table to move that contact to that company.
- Dragging items into different sections on a Kanban board to change the state of the record. See Making Kanban Boards.
Drag and Drop: Screen Setup
To set up drag and drop on components, a
Insert excerpt _
drag_
type _
drag_
type nopanel true
on the object you are dragging from and a
Insert excerpt _
drop_
target _
drop_
target nopanel true
Creating For Each Actions
Click and drag theThe 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
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.
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
See also:
Name: Invoices
Type: String
Expression: _result.value
hidden | true |
---|
on the object you are dropping onto is required. Components that can have drag types are grids and card components. Any component which has an actions tab can be a drop target. The action is configured on the drop target.
For example, to assign a new company to a contact a user creates two grids on a screen
- The contact and company table have a relationship and linked by a CompanyID field. The contact can be dragged and dropped onto a company to update CompanyID. The contact is the Drag Type and the company grid is the Drop Target.
Creating a Drag Type
- Open the properties for the view from which data will be dragged.
For example, right-click on the grid and select Show the View Configuration - Navigate to the Actions tab
In Action Settings → Drag Type, select or create a drag type, e.g. Move Contact.
Note This drag type needs to match the drag type defined on the drop target.
If using an actionflow, it is essential to add Drag Mappings to attributes from the source table to attributes used within the actionflow. If using table-actions, skip this step. In this example, we need to know the ID of the contact to be updated. To add Drag Mappings
Open the editor for the Drag Type by clicking on the field label
- Add an attribute and name this ContactID
- Change the Type to Integer
- Save the attribute
- In Action Settings → Drag Type Mappings, click
to open the mapping popup.Insert excerpt _mapping _mapping nopanel true - Map the ContactID from the Grid to ContactID on the Drag Type
Components with a drag type can be dragged and dropped onto any component which has a drop target with a matching drag type. It is on the drop target where the action is configured.
Creating a Drop Target
- Open the properties for the component where the data will be dropped. In the above example, this would be the Company grid.
- Navigate to the Actions tab.
- In Drop Targets, click
to create a new one.Insert excerpt _new _new nopanel true - Provide a descriptive name, such as Move Contact to New Company
- Select the drag type (e.g. Move Contact) which matches the drag type of the component being dragged.
- Select the action to run when something of the same drag type is dropped onto this component.
- If setting up a table-action see Using the Drag Type and Drop Target in a Record-Action below.
- If setting up an actionflow, see Using the Drag Type and Drop Target in an Actionflow below
HTML Comment | ||
---|---|---|
| ||
Worked Examples
Here's a worked example using the Company Data (available from the Learning Centre).
In this example, we are using:
- A Company For Each ExampleApproval Review screen containing:
- an multi-line string field and Save button that will be used by the user to enter a list
- a string field that will be used to create a filter
- a grid backed by the ForEachExample tablea grid backed by the Companies table
- with a Background Filter to only companies where their Status does not equal Approved or Rejected
- two areas containing Approve and Reject icons - 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 For Each ExampleApproval Review screen. |
Example 1: Approve Company Using Drag and Drop
In this example, we'll take a list of values inputted by a user and convert these into individual records.
Actionflow
configure company records on a grid to be draggable, and setup an area on a screen to as a drop target to receive the record(s). When a company is dropped in the area, its Status will be updated to Approved.
Drag Type Setup
- Open the Company For Each Example screenAdd an Approval Review screen
- Right-click on the Companies Pending Review grid and select
to the Save buttonInsert excerpt _view_show_actionflowconfig _view_actionflowshow_config nopanel true - Configure the Input as the CompanyForEachExample form
- Map the attribute Text into the Actionflow
Calculate Action - Convert List to Array
Use the split function in a- Click the
Insert excerpt _
property_
tabs _property_tabs name action
nopanel true
title | How? |
---|
- In the Action Settings section, click the
Insert excerpt _
add_
icon _
add_
icon nopanel true
- icon next to
Insert excerpt _
drag_type _drag_
totype nopanel true
- Map across the Text attribute
- create a new drag type:
- Name:
Split
Expand | ||
---|---|---|
| ||
Calculate Action - Create Session ID (Optional)
Create a SessionID attribute in a-
Company
-
Structured Data
split(in.Text,",")
- Attributes: select
Insert excerpt _
- Attributes: select
add_
icon _
add_
icon nopanel true
title | How? |
---|
- Name:
SessionID
-
CompanyID
- Type:
-
String
now() + _user.username
-
Integer
-
Insert excerpt _finish _finish nopanel true
Expand | ||
---|---|---|
| ||
For Each Action - Convert Array to Records
- A Drag Mappings section will become available in the Action Settings
- Click the
Insert excerpt _
mappings_
configure _
mappings_
configure nopanel true
- Create a button
- Map across the CompanyID attribute from the Companies
for_eachInsert excerpt _action_
for_eachview _action_
actionview nopanel true - Name:
Convert to Records
- Name:
- Connect it to the Calculate action and map across the Split attribute
- On the For Each action, enter the following:
- Input Expression:
in.Split
- Input Attributes:
Split
- Create two Output Attributes:
- Name:
Name
- Type:
String
- Expression:
trim(_result.value)
- The trim function is used here to remove the whitespace after the comma separator in the list
- If this was not used and the list "one, two, three" was entered, the records "two" and "three" would be saved with prefixed whitespace
- Type:
- Name:
LastUpdated
- Type:
Datetime
- Expression:
now()
- Type:
- Name:
- Input Expression:
- to the
Insert excerpt _drag_type _drag_type nopanel true - Click Confirm Mappings
Insert excerpt _finish _finish nopanel true
Expand | ||
---|---|---|
| ||
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.
- Open the the View
Drop Target Setup
Create an Output Attribute, UID, on the- On the Company Approval Review screen
- Click on the area holding the icon
- Ensure the
for your applicationExpand the area, OuterBorderTop, is selectedInsert excerpt _property_repositorysettings _repositoryproperty_settings nopanel true - Click the
Insert excerpt _property_sequencestabs _sequencesproperty_tabs name action nopanel true - option, then click In the Drop Targets section, click the
icon to add a new drop target:Insert excerpt _add_icon _add_icon nopanel true - Name:
Unique_ID
- Start Value:
1
- Block Size:
1
:CompanyApproval
- Drag Type: Select the Company Drag Type you set up above
- Drop Action:
Actionflow
- Actionflow: click
Insert excerpt _add_
icon _
add_icon nopanel true
- Name:
Add the Sequence Number to the UID Attribute (Optional)
to create a new Actionflow- Name:
Company Approval
- Name:
Actionflow Setup
- Connect the input of the Company
Insert excerpt _drag_type _drag_type nopanel true - Map in the CompanyID attribute
- Create a
Insert excerpt _action_
calculate _action_
actioncalculate nopanel true
- Name:
Update Status and Audit
- Name:
- Add three Output Attributes:
- NewApprovedStatus: this should contain the new
- NewUpdatedByName: this should contain details of the user making the change using the internal variable _user - see Internal Variables
- Review the existing table data to see the formatting of the attribute
NewUpdatedByTime: this should contain the date and time the user updates the record
Expand title How?
- Name:
UID
- Type:
Integer
- Expression:
nextValue('Unique_ID')
- Type:
Save Action
Use aCode Block theme Emacs title Name: NewApprovedStatus, Type: String "Approved"
Code Block theme Emacs title Name: NewUpdatedByName, Type: String _user.name + " (" + _user.fullUsername + ")"
Code Block theme Emacs title Name: NewUpdatedTime, Type: Datetime now()
Expand title Checkpoint
- Connect the
Insert excerpt _
input _
toinput nopanel true
title | How? |
---|
- the
Insert excerpt _action_
calculate _action_
actioncalculate nopanel true
- Hover over the Calculate action and click, out
- Click anywhere on the canvas to create a new
Insert excerpt _
action_
save _
action_
save nopanel true
Insert
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.
title | How? |
---|
- action
- Name:
Save Company
- Type:
Update
- Table:
Companies
- Name:
- Map across the three attributes created by the Calculate action onto their relevant attributes in the Companies table, and the CompanyID from the input
Expand | ||
---|---|---|
| ||
Filter Setup (Optional)
Create a Default Filter that filters the view by the values in the SessionID field
Expand | ||
---|---|---|
| ||
Testing
- On the Company For Each ExampleApproval Review screen,
the screenInsert excerpt _lock _lock nopanel true - Enter a list into the Text field, e.g. Extra Small, Small, Medium, Large, etc. and click Save
- Your list will be converted into individual records in the grid
- Enter another list and you will see that the previous list disappears as the grid is being filtered by the SessionID
- Once you have confirmed your default filter is working, hide it Drag a company from the Companies Pending Review grid onto the Approve icon
- The company should be removed from this screen and instead appear on the Companies screen
Example 2: Reject Company Using Drag and Drop (Optional)
Repeat the steps above to set up the Reject area as a Drop Target. Remember to change the Expression in the Output Attribute to "Rejected".