Versions Compared

Key

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

Insert excerpt
_Banners
_Banners
nameactionflow
nopaneltrue

By the end of this chapter you will understand what a Calculate action is and how to use them, and you will have created three Calculate Actionflows in your application.

What is a Calculate Action?

The 

Insert excerpt
_action_calculate
_action_calculate
nopaneltrue
 action manipulates and processes data. Calculate nodes have their own attributes, which can reference incoming data via expressions, using one or more of the 135+ Functions available in PhixFlow.

Creating Calculate Actions

  1. Click and drag the 
    Insert excerpt
    _action_calculate
    _action_calculate
    nopaneltrue
     icon from the toolbar onto the canvas
  2. Enter a name for the Calculate action, then select Create Action
  3. In the Calculate Action 
    Insert excerpt
    _property_settings
    _property_settings
    nopaneltrue
     on the right, click the 
    Insert excerpt
    _add_icon
    _add_icon
    nopaneltrue
     icon in the Output Attributes section to add new attributes
HTML Comment
hiddentrue

Insert excerpt
Calculate Node Properties
Calculate Node Properties
nopaneltrue


Tip

Calculate actions and their connection points, can have an attribute type of Structured Data. Use this if you need the Actionflow to pass a list (an array of values).

Example Uses

Calculate Actions can be used for: I HAVE UPDATED THE EXAMPLES

inserting

 

  • Inserting static text strings, e.g. when inserting a new record set a value of "New" in a status field
  • Calculating values using Functions, e.g. Calculating the amount of VAT on a customer invoice  
  • performing Performing lookups against a view View action node or lookup connection point, e.g. counting records in a grid or retrieving details of all students on a course

Worked Examples

Here's a worked example using the School Data (available from the Learning Centre). LINK DIRECTLY TO DOWNLOADS, CHECK OTHER LINKS. 

In this example, we are using:

  • Course Management screen containing a grid of the School Courses data - this screen was created using the Tile with Buttons template
  • Course Form screen containing form fields and associated with School Courses data by a background filter - this screen was created using the Edit Form template
Tip

If you are completing this chapter as part of the Actionflow course and using a training instance, this data has already been pre-loaded into the Actionflow Foundation ApplicationFor this example, we'll be working on buttons on the Course Management screen and the Course Form screen.

Example 1: Use a Calculate Action to Add Static Text

Earlier in this course we created an Actionflow that opens a blank input form for adding new courses to the School Courses grid. In this example we will enhance that Actionflow by adding the static text "New Course" to the blank input form.

Open the Course Management

We want to add a message, "Create New Course", to the Course Form header that shows only when a new course is being created. To do this, we will add a Calculate Action to the Open Screen Actionflow for adding a new course.

Image Added

  1. On the screen where the Actionflow will be initiated fromRight, Course Management, right-click on the  button on the School Courses grid and choose 
    Insert excerpt
    _actionflow_display
    _actionflow_display
    nopaneltrue
    1. If there is no Actionflow to display, see 1.07 Open Screen Action Configuration
  2. Click and drag the 
    Insert excerpt
    _action_calculate
    _action_calculate
    nopaneltrue
     icon from the toolbar onto the canvas
  3. Enter a name for the Calculate Action:
    1. Name: Course Header
    2. Select Create Action 
  4. The 
    Insert excerpt
    _property_tabs
    _property_tabs
    nopaneltrue
     for the Calculate Action will open on the right
    1. If the 
      Insert excerpt
      _property_tabs
      _property_tabs
      nopaneltrue
      is not open, click the Calculate Action node on the canvas 
  5. In the Output Attributes section, click the 
    Insert excerpt
    _add_icon
    _add_icon
    nopaneltrue
     icon
  6. Enter the following details for the new Output Attribute:
    1. Name: NewCourse
    2. Type: choose String
    3. Expression: 

      Code Block
      themeEmacs
      "Create New Course"


    4. Then 
      Insert excerpt
      _finish
      _finish
      nopaneltrue
  7. Drag and drop the Course Header Calculate Action onto the connector between the input node and the Open Course Form Action
  8. Right-click on the connector between the Course Header Calculate Action and the Open Course Form Open Screen Action and choose
    Insert excerpt
    _open_mappings
    _open_mappings
    nopaneltrue
  9. On the Mappings window, drag the NewCourse attribute onto the Heading attribute Header1Dynamic attribute to create the mapping
    1. Press Save
    2. Image RemovedImage Added
  10. Close the Actionflow to return to the Course Management screen
  11. Insert excerpt
    _lock
    _lock
    nopaneltrue
     the screen and press the  button to see the Actionflow in action
    1. We can see that the Actionflow is working because it displays the string, Create New Course, in place of the original heading on the input form  Course Form 

Example 2: Use a Calculate Action to Perform a

Function (Optional)

Function 

In this example, we will configure a button to run an Actionflow that uses the now function to insert today's date into a dynamic text field. This example uses no data for the input.

Setup the Input and Calculate Action

Description?

On the Course Management screen open the Insert excerpt_layers_layersnopaneltrue and expand the area, Screen HeaderExpand the area, Right, and you

will

see two components - a button and a dynamic text fieldClick on the button, Button Date, in the  Insert excerpt_layers_layersnopaneltrue to highlight it on the screenRight-click on the button on the screen and choose  Insert excerpt_actionflow_add_actionflow_

add

nopaneltrueEnter

a

name for the Actionflow,
  1. Name: Populate Date Field
  2. Select Confirm
Select Click to Connect and for the input, choose the  Insert excerpt_actionflow_on_click_actionflow_on_clicknopaneltrue Action Event, then select Connect InputClick and drag the  Insert excerpt_action_calculate_action_calculatenopaneltrue icon from the toolbar onto the canvas
  • Enter a name for the Calculate Action:
    1. Name: Get Date
    2. Select Create Action 
  • The  Insert excerpt_property_tabs_property_tabsnopaneltrue for the Calculate Action will open on the rightIn the Output Attributes section, click the  Insert excerpt_add_icon_add_iconnopaneltrue iconEnter the following details for the new Output Attribute:
  • Name: TodayDate
  • Type: choose String
  • Expression: 

    Code Block
    now()
    Then  Insert excerpt_finish_finishnopaneltrue
  • Click and drag the input onto the Get Date Calculate Action
  • Setup the Output and Write Back to the Screen

    DESCRIPTION?

    In the Connections panel on the left, click Insert excerpt_addIcon_addIconnopaneltrue Add to create a new connection point
  • Enter the following details for the new connection point:
    1. Name: out
    2. Type: choose Output
    3. Select Create Connection Point
  • Select Click to Connect and for the output, choose the  Insert excerpt_form_formnopaneltrue datasource
    1. Select Connect Output
  • Close the Mappings window that automatically opens
  • Hover over the Calculate Action node and select out
  • A red arrow will appear - click on the Insert excerpt_output_outputnameiconnopaneltrue output node under Connections
  • On the Mappings window, drag the attribute, TodayDate, from the left (Calculate Action) to the right (output connection point) to create an attribute on the output
    1. Select Save
  • Under Connections, right-click on the connector, out, and choose Insert excerpt_mappings_configure_mappings_configurenopaneltrue
  • Drag the TodayDate attribute from the left (output connection point) and drop it onto the DateField target parameter on the right (Course Management screen)
    1. Select Save
  • Close the Actionflow to return to the Course Management screen
  • Insert excerpt_lock_locknopaneltrue the screen and press the Button Date on the screen to see the Actionflow in action
    1. We can see that the Actionflow is working because it displays today's date in the format DD/MM/YY in the DateField dynamic text field

    Use a Calculate Action to Perform a Function 

    In this example, we will modify the Save Actionflow we created in an earlier chapter to perform the function, toUpper, which will format the course name into upper case. This example uses data for the input.Calculate Action that performs the function, toUpper, to a Save Actionflow. This function will format the course name on the Course Management screen into upper case, when the course is added/edited. 

    Image Added

    Setup the Input 

    1. On the Course Management screen, click the  or  button to open the Course Form
    2. Right-click on the  button and select 
      Insert excerpt
      _actionflow_display
      _actionflow_display
      nopaneltrue
    3. Click and drag the 
      Insert excerpt
      _action_calculate
      _action_calculate
      nopaneltrue
       icon from the toolbar onto the canvas
    4. Enter a name for the Calculate Action:
      1. Name: UppercaseName
      2. Select Create Action
    5. Right-click on the input connection point under Connections and choose 
      Insert excerpt
      _mappings_configure
      _mappings_configure
      nopaneltrue
    6. On the Mappings window, drag the attribute, Name, from the left (Course Form) into the Drag and Drop space on the right (input connection point) 
      1. Select Save
    7. On the canvas, drag the UppercaseName Calculate Action node onto the in connector between the 
      Insert excerpt
      _input
      _input
      nopaneltrue
       
      node and thethe 
      Insert excerpt
      _save_icon
      _save_icon
      nopaneltrue
       SaveCourse
      node and drop it when the 
      Insert excerpt
      _add_icon
      _add_icon
      nopaneltrue
       icon appears
    8. Right-click on the in connector between the 
      Insert excerpt
      _input
      _input
      nopaneltrue
       
      node and the 
      Insert excerpt
      _actionflow_calculate
      _actionflow_calculate
      nopaneltrue
       and select 
      Insert excerpt
      _open_mappings
      _open_mappings
      nopaneltrue
    9. On the Mappings window, drag the Name attribute from the left to the right (calculate action)

      Tip

      We only need to map the Name attribute here because it is used within the Calculate Action.

      The CourseID attribute will pass through the Calculate Action and can be used later on in the Actionflow.


      1. Select Save


    Expand
    titleCheckpoint

    Image Added

    Setup the Calculate Action 

    1. Select the Calculate Action, UppercaseName, to open itsits 
      Insert excerpt
      _property_settings
      _property_settings
      nopaneltrue
    2. In the Output Attributes section, click click the 
      Insert excerpt
      _addIcon
      _addIcon
      nopaneltrue
       to create a new attribute:
      1. Name: UpperName
      2. Type: choose String
      3. Expression:

        Code Block
        themeEmacs
        toUpper(in.Name)



      4. Click 

        Insert excerpt
        _finish
        _finish
        nopaneltrue

    3. Right-click on the in connector between the 
      Insert excerpt
      _actionflow_calculate
      _actionflow_calculate
      nopaneltrue
       
      action node and the 
      Insert excerpt
      _action_save
      _action_save
      nopaneltrue
       and  action node, and select 
      Insert excerpt
      _open_mappings
      _open_mappings
      nopaneltrue
    4. On the Mappings window, drag the attribute, UpperName, from the Calculate Action (left) onto the Name attribute on the Save Action (right)
      1. Press Save

        Expand
        titleCheckpoint

        Image Added


    5. Close the Actionflow to return to the Course Form
    6. Ensure the screen is 
      Insert excerpt
      _lock
      _lock
      nopaneltrue
      ed, then add or edit the course details and press the  button to see the Actionflow in action
      1. You can see that the Actionflow is working because the Name for the course you just added/edited is now in capital letters on the School Courses grid Course Management screen


    Image Modified