Versions Compared

Key

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

Insert excerpt
_Banners
_Banners
nameactionflow
nopaneltrue

What is a For Each Action?

Image Removed

The  Insert excerpt_action_foreach_action_foreachnopaneltrue action iterates over a set of records or list of values, and generates an output record for each one. It is most commonly used to split data, such as an array, into individual records, or it can be used in conjunction with

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

  1. To set up drag and drop on components,

    Insert excerpt
    _

action
  1. drag_

calculate
  1. type
    _

action
  1. drag_

calculate
  1. type
    nopaneltrue

 action to firstly convert a user-inputted list into an array for the 
  1.  on the object you are dragging from and a 

    Insert excerpt
    _

action
  1. drop_

for_each
  1. target
    _

action
  1. drop_

for_each
  1. target
    nopaneltrue

 action to process - see worked example below.   

Creating For Each Actions

Click and drag the  Insert excerpt_action_foreach_action_foreachnopaneltrue icon from the toolbar onto the canvas
  • Enter a name in the Create For Each Action window and select Create Action
  • In the  Insert excerpt_action_foreach_action_foreachnopaneltrue action  Insert excerpt_property_settings_property_settingsnopaneltrue on the right, populate the following:FieldDescriptionExample ValueInput Expression

    The 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     

    Input Attributes

    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.

    Output Attributes

    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

    To work in a larger popup window, click  Insert excerpt_editor_expand_editor_expandnopaneltrue.

    See also:

    Name: Invoices

    Type: String 

    Expression: _result.value

    HTML Comment
    hiddentrue
    Insert excerptFor Each NodeFor Each NodenamepagenopaneltrueWorked Example
    1.  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

    2. 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

    1. 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
    2. Navigate to the Actions tab
    3. 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


    4. 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

      1. Open the editor for the Drag Type by clicking on the field label

      2. Add an attribute and name this ContactID 
      3. Change the Type to Integer
      4. Save the attribute
      5. In Action Settings → Drag Type Mappings, click 
        Insert excerpt
        _mapping
        _mapping
        nopaneltrue
        to open the mapping popup.
      6. 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

    1. Open the properties for the component where the data will be dropped. In the above example, this would be the Company grid.
    2. Navigate to the Actions tab.
    3. In Drop Targets click 
      Insert excerpt
      _new
      _new
      nopaneltrue
        to create a new one
      .
      1. Provide a descriptive name, such as Move Contact to New Company
      2. Select the drag type (e.g. Move Contact) which matches the drag type of the component being dragged.
      3. Select the action to run when something of the same drag type is dropped onto this component. 
      4. If setting up a table-action see Using the Drag Type and Drop Target in a Record-Action below.
      5. If setting up an actionflow, see Using the Drag Type and Drop Target in an Actionflow below


    HTML Comment
    hiddentrue


    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.

    Split a List Into Individual Records

    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.

    Image Removed

    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.

    Image Added

    Drag Type Setup

    1. Open the Company For Each Example screenAdd an Approval Review screen
    2. Right-click on the Companies Pending Review grid and select 
      Insert excerpt
      _view_show_actionflowconfig
      _view_actionflowshow_config
      nopaneltrue
       to the Save button
    3. Configure the Input as the CompanyForEachExample form
    4. Map the attribute Text into the Actionflow

    Calculate Action - Convert List to Array

    Use the split function in a 
    1. Click the 
      Insert excerpt
      _
    action
    1. property_
    calculate
    1. tabs
      _property_tabs
      nameaction
    _calculateCreate a 
    1. nopaneltrue
     action to split the Text attribute by the comma separator. This will convert the list entered by the user into an array. Expand
    titleHow?
    1. In the Action Settings section, click the 
      Insert excerpt
      _
    action
    1. add_
    calculate
    1. icon
      _
    action
    1. add_
    calculate
    1. icon
      nopaneltrue
     actionConnect the 
    1.  icon next to 
      Insert excerpt
      _
    input
    1. drag_type
      _drag_
    input
    1. type
      nopaneltrue
       to
    the Calculate action
    1. Map across the Text attribute
    In the Calculate action, create an Output Attribute
    1. create a new drag type:
      1. Name:
    Split
    Expand
    titleCheckpoint

    Image Removed

    Calculate Action - Create Session ID (Optional)

    Create a SessionID attribute in a 
      1. Company
  • Type: Structured Data
  • Expression: split(in.Text,",")
      1. Attributes: select 
        Insert excerpt
        _
    action
      1. add_
    calculate
      1. icon
        _
    action
      1. add_
    calculate
      1. icon
        nopaneltrue
     action to allow identification of records created at the same time, which we will use for filtering. Expand
    titleHow?
    In the Calculate action, create another Output Attribute:
        1. Name:
    SessionID
        1. CompanyID
        2. Type:
    String
  • Expression: now() + _user.username
  • Use a 
        1. Integer
      1. Insert excerpt
        _finish
        _finish
        nopaneltrue
    Expand
    titleCheckpoint

    Image Removed

    For Each Action - Convert Array to Records

    1. A Drag Mappings section will become available in the Action Settings
    2. Click the 
      Insert excerpt
      _
    action
    1. mappings_
    for_each
    1. configure
      _
    action
    1. mappings_
    for_each
    1. configure
      nopaneltrue
     action to convert the array into individual records.
    1. Create a  button
    2. Map across the CompanyID attribute from the Companies
      Insert excerpt
      _action_
      for_each
      view
      _action_
      for_each
      view
      nopaneltrue
       action 
      1. Name: Convert to Records
    3. Connect it to the Calculate action and map across the Split attribute
    4. On the For Each action, enter the following:
      1. Input Expression: in.Split
      2. Input Attributes: Split
      3. Create two Output Attributes: 
        1. Name: Name
          1. Type: String
          2. Expression: trim(_result.value)
            1. The trim function is used here to remove the whitespace after the comma separator in the list
            2. If this was not used and the list "one, two, three" was entered, the records "two" and "three" would be saved with prefixed whitespace
        2. Name: LastUpdated
          1. Type: Datetime
          2. Expression: now()
    5.  to the 
      Insert excerpt
      _drag_type
      _drag_type
      nopaneltrue
    6. Click Confirm Mappings
    7. Insert excerpt
      _finish
      _finish
      nopaneltrue
    Expand
    titleCheckpoint
    Image Removed

    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.

    1. Open the  the View

    Drop Target Setup

    Create an Output Attribute, UID, on the
    1. On the Company Approval Review screen
    2. Click on the area holding the Image Added icon
    3. Ensure the
      Insert excerpt
      _property_repositorysettings
      _repositoryproperty_settings
      nopaneltrue
       for your applicationExpand the area, OuterBorderTop, is selected
    4. Click the 
      Insert excerpt
      _property_sequencestabs
      _sequencesproperty_tabs
      nameaction
      nopaneltrue
    5.  option, then click In the Drop Targets section, click the 
      Insert excerpt
      _add_icon
      _add_icon
      nopaneltrue
       icon to add a new drop target:
      1. Name: Unique_ID
      2. Start Value: 1
      3. Block Size: 1: CompanyApproval
      4. Drag Type: Select the Company Drag Type you set up above
      5. Drop Action: Actionflow
      6. Actionflow: click 
        Insert excerpt
        _add_
      finish
      1. icon
        _
      finish
      1. add_icon
        nopaneltrue

    Image Removed

    Add the Sequence Number to the UID Attribute (Optional)

      1.  to create a new Actionflow
        1. Name: Company Approval

    Actionflow Setup

    1. Connect the input of the Company 
      Insert excerpt
      _drag_type
      _drag_type
      nopaneltrue
    2. Map in the CompanyID attribute 
    3. Create a 
      Insert excerpt
      _action_
    for_each
    1. calculate
      _action_
    for_each
    1. calculate
      nopaneltrue
       action
    using the Sequence you created above. 
      1. Name: Update Status and Audit
    1. Add three Output Attributes:
      1. NewApprovedStatus: this should contain the new 
      2. NewUpdatedByName: this should contain details of the user making the change using the internal variable _user - see Internal Variables
        1. Review the existing table data to see the formatting of the attribute
      3. NewUpdatedByTime: this should contain the date and time the user updates the record

        Expand
        titleHow?
  • On the For Each action, create an Output Attribute: 
    1. Name: UID
      1. Type: Integer
      2. Expression: nextValue('Unique_ID')
  • Insert excerpt_finish_finishnopaneltrue

    Save Action 

    Use a 

      1. Code Block
        themeEmacs
        titleName: NewApprovedStatus, Type: String
        "Approved"


        Code Block
        themeEmacs
        titleName: NewUpdatedByName, Type: String
        _user.name + " (" + _user.fullUsername + ")"


        Code Block
        themeEmacs
        titleName: NewUpdatedTime, Type: Datetime
        now()



        Expand
        titleCheckpoint

    Image Removed

      1. Image Added


    1. Connect the 
      Insert excerpt
      _
    action_save
    1. input
      _
    action_save
    1. input
      nopaneltrue
       to
    save the data to the ForEachExample table. Expand
    titleHow?
    Create a 
    1. the 
      Insert excerpt
      _action_
    save
    1. calculate
      _action_
    save
    1. calculate
      nopaneltrue
       action
    for the ForEachExample table
  • Connect it to the For Each action
  • Map across all attributes from the For Each action
  • Map across the SessionID attribute from the Calculate action, if created
  • In the Save action 
    1. Hover over the Calculate action and click, out
    2. Click anywhere on the canvas to create a new 
      Insert excerpt
      _
    property
    1. action_
    settings
    1. save
      _
    property
    1. action_
    settings
    1. save
      nopaneltrue
    , change the Type to Insert

    Image Removed

    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.

    Expand
    titleHow?
  • Under Connections, create an output connection point to the CompanyForEachExample form
  • Hover over the Save action and click, out, then select the  Insert excerpt_output_outputnopaneltrue node
  • Map across the SessionID attribute from the table (not the Calculate action) to the output
  • Click on the output connector under Connections and map the SessionID attribute from the output to the screen
    1.  action
      1. Name: Save Company
      2. Type: Update
      3. Table: Companies
    2. 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
    titleCheckpoint

    Image Removed

    Filter Setup (Optional)

  • On the Company For Each Example screen, open the view configuration for the grid
  • Create a Default Filter that filters the view by the values in the SessionID field

    Expand
    titleHow?

    Image Removed

    Image Added

    Testing

    1. On the Company For Each ExampleApproval Review screen, 
      Insert excerpt
      _lock
      _lock
      nopaneltrue
       the screen
    2. Enter a list into the Text field, e.g. Extra Small, Small, Medium, Large, etc. and click Save
      1. Your list will be converted into individual records in the grid
    3. Enter another list and you will see that the previous list disappears as the grid is being filtered by the SessionID 
    4. Once you have confirmed your default filter is working, hide it Drag a company from the Companies Pending Review grid onto the Approve icon
      1. 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".

    Image Added

    3.09 Loop Action Configuration