In this post, you’ll learn everything about the Workflow Action “Calculated Fields” and how to use it effectively to perform calculations, identify text, and format data.
What are Calculated Fields?
This function is based on a defined set of formulas that allow you to perform complex transformations. It consists of three main components: Parameters, Relation Parameters, and Formulas.
1. Parameters
Parameters are the fields of the workflow module that you can use for your calculations. These parameters are included in formulas using the format `{P0}`. When you add a new parameter, the interface will display which parameter the respective field has. This way, you always have full control over how the data is used in your calculations.
2. Relation Parameters
Relation Parameters give you access to all one-to-many relationships of the module and their fields. These are included in formulas using the format `{R0}`. This allows you to evaluate and consider data from related records. It gives you the ability to perform more complex data analyses and transformations.
3. Formulas
Under Formulas, you define the specific formula that should be applied to a particular field. First, select the corresponding field and then enter the formula in the text line. You can nest multiple formulas within each other or chain them together. To do this, simply add another formula in place of a parameter part in another formula, or append a new formula to your previous one. It’s important to ensure that the notation is correct, as otherwise the evaluation could fail.
4. Escaping Semicolons
Why Do You Need an Escape Semicolon?
In the DataEngine, the semicolon (;) serves as a delimiter for parameters in formulas. This means that when entering a formula like: {position(subject; search; occurrence)} the semicolons separate the individual parameters within the formula.
However, there are situations where a semicolon needs to be used as part of a value without being interpreted as a delimiter. For such cases, we provide a special character known as the Escape Semicolon \;.
How to Use the Escape Semicolon
To correctly include a semicolon within a value without disrupting the formula structure, the Escape Semicolon \; must be used. An example applying the escape mechanism in the previous formula:
{position(subject; \; ; occurrence)}
Here, the Escape Semicolon \; ensures that the system interprets the semicolon as part of the value rather than as a formula delimiter. This guarantees that the formula accurately identifies the position of the semicolon within the subject text.
Supported Formula Categories
- Logical Functions: These yield values of 0 or 1 and are ideal for comparisons like “equal” or “greater than or equal to.”
- Text Functions: Use these to transform text in different forms.
- Mathematical Functions: Utilize all common mathematical operations to transform numbers.
- Date Functions: These are useful for transforming date values or setting them based on certain conditions.
- Control Functions: With the ifThenElse function, you can perform complex queries and conditional checks. Nestings are possible here to consider multiple conditions.
- Counter Functions: These functions count records within the system and add counters to them.
- JSON Functions: JSON Arrays can be transformed according to specific rules, and specific values can be extracted.
- PHP Functions: These functions can be used to transform PHP arrays.
With this overview, you are well-equipped to optimally use Calculated Fields in your workflows.