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 Calculate 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
- Click and drag the Calculate icon from the toolbar onto the canvas
- Enter a name for the Calculate action, then select Create Action
- In the Calculate Action Properties on the right, click the icon in the Output Attributes section to add new attributes
Example Uses
Calculate Actions can be used for:
- inserting static text strings, e.g. inserting a new record into a grid containing the string "new"
- performing Functions, e.g. adding debug messages to the System Console
- performing lookups, e.g. counting records in a grid
Worked Examples
Here's a worked example using the School Data (available from the Learning Centre).
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 Application.
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 screen where the Actionflow will be initiated from
- Right-click on the button on the School Courses grid and choose Display Actionflow
- Click and drag the Calculate icon from the toolbar onto the canvas
- Enter a name for the Calculate Action:
- Name:
Course Header
- Select Create Action
- Name:
- The Properties tab for the Calculate Action will open on the right
- If the Properties tab is not open, click the Calculate Action node on the canvas
- In the Output Attributes section, click the icon
- Enter the following details for the new Output Attribute:
- Name:
NewCourse
- Type: choose
String
Expression:
"Create New Course"
- Then Apply and Close
- Name:
- Drag and drop the Course Header Calculate Action onto the connector between the input node and the Open Course Form Action
- Right-click on the connector between the Course Header Calculate Action and the Open Course Form Open Screen Action and choose Open Mappings
- On the Mappings window, drag the NewCourse attribute onto the Heading attribute to create the mapping
- Press Save
- Close the Actionflow to return to the Course Management screen
- Lock the screen and press the button to see the Actionflow in action
- We can see that the Actionflow is working because it displays the string, New Course, in place of the original heading on the input form
Use a Calculate Action to Perform a Function (Optional)
In this example, we will configure a button to run an Actionflow that performs the now function, which will insert today's date into a dynamic text field. This example uses no data for the input.
Setup the Input and Calculate Action
- On the Course Management screen open the Layers and expand the area, Screen Header
- Expand the area, Right, and you will see two components - a button and a dynamic text field
- Click on the button, Button Date, in the Layers to highlight it on the screen
- Right-click on the button on the screen and choose Add Actionflow
- Enter a name for the Actionflow,
- Name:
Populate Date Field
- Select Confirm
- Name:
- Select Click to Connect and for the input, choose the On Click Action Event, then select Connect Input
- Click and drag the Calculate icon from the toolbar onto the canvas
- Enter a name for the Calculate Action:
- Name:
Get Date
- Select Create Action
- Name:
- The Properties tab for the Calculate Action will open on the right
- In the Output Attributes section, click the icon
- Enter the following details for the new Output Attribute:
- Name:
TodayDate
- Type: choose
String
Expression:
now()
- Then Apply and Close
- Name:
- Click and drag the input onto the Get Date Calculate Action
Setup the Output and Write Back to the Screen
- In the Connections panel on the left, click Add to create a new connection point
- Enter the following details for the new connection point:
- Name:
out
- Type: choose
Output
- Select Create Connection Point
- Name:
- Select Click to Connect and for the output, choose the Form datasource
- 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 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
- Select Save
- Under Connections, right-click on the connector, out, and choose Configure Mappings
- Drag the TodayDate attribute from the left (output connection point) and drop it onto the DateField target parameter on the right (Course Management screen)
- Select Save
- Close the Actionflow to return to the Course Management screen
- Lock the screen and press the Button Date on the screen to see the Actionflow in action
- 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.
Setup the Input
- On the Course Management screen click the or button to open the Course Form
- Right-click on the button and select Display Actionflow
- Click and drag the Calculate icon from the toolbar onto the canvas
- Enter a name for the Calculate Action:
- Name:
UppercaseName
- Select Create Action
- Name:
- Right-click on the input connection point under Connections and choose Configure Mappings
- 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)
- Select Save
- On the canvas, drag the UppercaseName Calculate Action node onto the in connector between the input node and the SaveCourse node and drop it when the icon appears
- Right-click on the in connector between the input node and the Calculate and select Open Mappings
- On the Mappings window, drag the Name attribute from the left to the right (calculate action)
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.
- Select Save
Setup the Calculate Action
- Select the Calculate Action, UppercaseName, to open its Properties
- In the Output Attributes section, click to create a new attribute:
- Name:
UpperName
- Type: choose String
Expression:
toUpper(in.Name)
- Name:
- Right-click on the in connector between the Calculate node and the Save and select Open Mappings
- On the Mappings window, drag the attribute, UpperName, from the Calculate Action (left) onto the Name attribute on the Save Action (right)
- Press Save
- Close the Actionflow to return to the Course Form
- Ensure the screen is Locked, then add or edit the course details and press the button to see the Actionflow in action
- 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