17.14 Field Formulas
Field Formulas are custom fields that handle simple calculations and generate the result directly in a specially created field. To start, simply go to Settings> Desired Module (e.g. Accounts) and click on "New Field Expression".
This wording will not be present unless we have previously created a field to use for the result. This will be clear because instead of the "New Expression Field" button, we'll find the words "You need to add a string field or an entire Custom Field".
Going to the Layout editor of the Accounts module, you can prepare the fields that are suitable for our purpose, for example, to calculate the total number of employees by adding the internal ones to external ones.
Then, from the Field Formulas, select the Target field (i.e. the field in which the total number of employees will be printed) and set the expression as follows (the fields chosen will be, in fact, Number of internal employees and Number of external employees):
In the Accounts module, the result will be as follows:
In the formulas you can use all algebraic operators: plus (+), minus (-), divided by (/), multiplied by (*).
It is also possible to configure If/Else controls following the structure:
if condition then true_case else false_case end
It is also possible, however, to make expressions with date type fields; there are two operators in particular:
time_diffdays: gives the difference in days between two dates
time_diff: gives the difference in seconds between two dates.
Note. If only one parameter is entered in the time_diff and time_diffdays functions, the value returned in the Field Formula is the difference between the current date and the date entered in the parameter.
For example, for custom field C, you want it to store the number of days since the last phone contact of the Company.