The formula window in the business process element settings enables you to solve many tasks without developer involvement. The functions of the formula range from automatically generating email message texts, determining the conditions for transitions between flows. Using formulas requires knowledge of basic syntax rules, which are covered in this article.
Basic syntax rules
The formula syntax will be familiar to anyone who worked with C#. When entering formulas, it is important to follow typing. If possible, use values of one type, for example, text values with text values, numeric values with numeric values. Otherwise, you must convert values to the proper type.
In addition, we recommend you to familiarize yourself with the basic operators that will help to implement complex conditions in your formulas.
"" |
Text strings must be enclosed in quotes. |
+ |
Used to connect values. |
== |
Defines the equality of two values. |
!= |
Defines the inequality of two values. |
<, > |
Compares the two values (less than, greater than). |
>=, <= |
Compares the two values (greater or equal, less or equal). |
&& |
Boolean “And.” |
|| |
Boolean “Or.” |
true, false |
Boolean values “True” and “False.” |
\n, <br> |
Text line wrap. |
Build a complex text
The Formula field is usually used to generate variable text.
To do this, add the Read data element parameters and constant text values to the formula:
You can combine two and more strings using the formula dialog. Use the + character for concatenation. To introduce a new line, use the \n control character, for example:
String literals must always be wrapped in straight double quotes (" "). To ensure that control characters work as intended, check the “Is multiline” box. Otherwise, all newline characters will be filtered.
Use different types of data
When working with the Formula element, use a single type of data. There is no need to memorize the typification — on the formula edit page, the data type of each parameter is marked with:
— unique identifier;
— numeric;
— fractional;
— text;
— lookup value;
— time and date value.
In this case, the compilation date parameter cannot be added in the usual way. To do this, you need to convert the date value to the text value:
To convert the #Read order.The first element of the resulting collection.Planned date of completion# parameter, enclose it in parentheses and add the .ToString() property. In this case, the business process will work correctly.
Use date and time parameters
To execute business processes with the use of operations with date and time, you can use the C# DateTime structure. The main characteristics and methods are as follows:
.Date |
Returns the date value of the selected parameter. |
.Hour |
Returns the hours value of the selected date parameter. |
DateTime.MinValue |
The minimum value of date and time, 00:00, UTC, January 1, 0001. |
.TotalMinutes |
Returns the full date and time value in minutes. |
.TotalHours |
Returns the full date and time value in hours. |
.TotalDays |
Returns the full date and time value in days. |
.AddMinutes(), .AddHours(), .AddDays() |
Increase the selected value of the date and time for a certain number of minutes, hours or days. |
To check whether a date field is populated, use the != operator and the DateTime.MinValue parameter:
To compare two date values, use the == operator and the .Date property:
If you need to calculate the difference between two date values, use the following construct:
In the formula window, select the RoundOff function and fill it in with the necessary process element parameters, in our case, the difference of values, and then add the .TotalMinutes property. As a result, you will get the elapsed time in minutes. Use the .TotalHours or .TotalDays properties to obtain same result in hours or days.
To do this, add the.TotalHours property to the element parameter, enclose the parameter value in parentheses, and then compare it with a numeric value:
When working with date and time parameters, you can also use .AddMinutes(), .AddHours() and .AddDays() functions to increment the time and date to a certain value. For example, you can bring the date and time value to user’s time zone when using the Read data element.
To do this, add the number of hours in the .AddHours() value:
Work with lookup parameters and conditional flows
The functionality of the Formula element in a conditional flow is same as in other process elements. That is, the basic rules and operators are relevant. Conditional flows are used to transition to the next process element, if transition conditions are met.
Often, values of the lookup parameters must be compared with a specific lookup value.
To do this, compare the current opportunity stage in the conditional flow with the value in the lookup:
To check whether the lookup field is populated, use the following condition:
To check whether the lookup field is not populated, use the following construct:
To do this, use the following condition:
In this case, the approval result is checked.
Note that there may be several solutions of this case. For example, you can use a more complex structure:
In this case, Creatio checks whether the approval status is not “Rejected” or “Approval pending.”
To check the status of your presentation, use the following structure:
If the presentation has not been conducted, the conditional flow will not be activated.