Perform calculations on-demand
In Flowfinity, formula calculations can either be
- recalculated whenever a record is modified; or
- calculated on-demand at specific steps in business workflows, such as when a record is first created.
On-demand calculations are accomplished through calculated defaults. With calculated defaults, you also have the option to make the calculated field editable by the user.
To set up a calculated default value, simply click "Abc" on the right of the default value of a field, select “calculated value” from the menu, and type in the formula.
Example 1
A common use case for calculated defaults is capturing each date a record was modified, for records that are modified several times.
In this inspection application, a single record is created for each site, and the different inspections for that site that occur over a period of time are recorded into a nested field.
Each time an inspection is performed, the inspector adds a new item in the nested field with the inspection results. The inspection date and time are automatically calculated when the item is added.
Instructions
- Customize your application.
- In the Form section, add a Nested field.
- Click the button "Customize nested form."
- Add a date field to the nested form.
- In the "Default value" of the field, click "Abc" on the right and select "Calculated value." Ensure that this is done within the "Default value" and not the field "Type."
- Type in the formula. In this example, the formula currentdatetime() will capture the date and time a new item is added to the nested list.
- In the Layout section of the same field, click the checkmark in the "Editable" column and change the answer to "No." This will ensure that users can't change the inspection date or time once it's captured.
- Save the form, and publish the application.
Example 2
Another use case involves resetting a field to its calculated default value each time a certain layout is used. This lets you control specifically when the default value should be calculated, during specific operations or steps in your workflows.
In this example, an inspection report will be sent to a customer several times over a period of time, when an inspection update is made. A calculated default will be used to capture the date and time the report was last sent to the customer.
- Customize the application
- In the Form section, click on the "Layouts" link and then the Add Layout button to add a new layout.
- Specify the name of the new layout, such as "Send to Customer."
- If needed, add a new Page to organize the fields that will be used when sending reports to the customers. You can control the settings (included, visible, editable, mandatory), for individual fields or entire pages, for each layout.
- Add the field "Last Sent to Customer Date." Click on the "Abc" next to the default value, and type the formula currentdatetime().
- Under Layouts, click on the menu in the "Included" column, and select "Yes, reset." This setting means that each time this layout is used, the field will be recalculated to its default value.
- Next, go into the Operations section and create an operation that uses this layout, such as an Edit operation called "Send Update to Customer." In "Display record in this layout", select the layout you created "Send to Customer."
- Publish the application.