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
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:
- 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 lookups against a 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).
In this example, we are using:
- A Course Management screen containing a grid of the School Courses data - this screen was created using the Tile with Buttons template
- A 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
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 Application. For 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
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.
- On the screen where the Actionflow will be initiated from, Course Management, right-click on the button on the School Courses grid and choose Display Actionflow
- If there is no Actionflow to display, see 1.07 Open Screen Action Configuration
- 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 Header1Dynamic 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, Create New Course, in place of the original heading on the Course Form
Example 2: Use a Calculate Action to Perform a Function
In this example, we will add a 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.
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 the to create a new attribute:
- Name:
UpperName
- Type: choose String
Expression:
toUpper(in.Name)
Click Apply and Close
- Name:
- Right-click on the in connector between the Calculate action node and the Save action node, 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 Course Management screen