This topic explains the structure of formulas used in Formula attributes, which are created and managed in the Objects and Attributes section of the Administration module.
To create a Formula attribute, first the format of the value to be calculated must be selected in the Formula Output field. The output options available are Date/Time, Number, and Text.
Formulas can be comprised of one or more lines, with expressions separated by semicolons (;). Each line is executed in a sequential order and the value returned is calculated according to the result of the last line executed. The most common syntax for writing formulas is shown below, with [#x] as optional:
[variableA] = <expression 1>;
[variableB] = <expression 2>;
…
[variableZ] = <expression N>;
The variables in the above example can be created to streamline the writing of the formula by inserting the pound sign ("#"). For example:
#variable_created_by_user = 1;
#expression = #variable_created_by_user * @object_attribute + 10;
#expression
In each expression, the properties from the object and its custom attributes can be used as variables, except for Attachment, Formula, Image, Outline, and Relationship attributes. The properties and attributes of the object for which the attribute is being created will be available for use through the Variables field. The variables from custom attributes associated with the object are preceded by the "@" symbol.
For more detailed information on the syntax of these formulas, access the following link:
http://www.springframework.net/doc-latest/reference/html/expressions.html.
The tables below list the operators and functions available and their descriptions:
Relational Operators |
Description |
== |
Returns true if two elements are equal and false if otherwise. For example: "#result = #var == 1" |
!= |
Returns true if two elements are different and false if otherwise. For example: "#result = #var != 1" |
< |
Returns true if the element on the left is less than or equal to the element on the right. For example: "#result = #var < 1" |
<= |
Returns true if the element on the left is less than or equal to the element on the right. For example: "#result = #var < = 1" |
> |
Returns true if the element on the left is greater than the element on the right. For example: "#result = #var > 1" |
>= |
Returns true if the element on the left is greater than or equal to the element on the right. For example: "#result = #var > = 1" |
in |
Returns true if the element is contained in the array. For example: "#result = 3 in {1,2,3,4}" |
between |
Returns true if the element is contained in the interval specified. For example: "#result = 3 between {1,4}" |
Logical Operators |
Description |
or |
Returns true if a condition is met. For example: "#result = (#var == 1) or (#var == 2)" |
and |
Returns true if all conditions are met. For example: "#result = (#var != 1) and (#var != 2)" |
! |
Negates the Boolean result of an expression. If the result is true, it returns false. If false, it returns true. For example: "#result = !(2 == 1)" |
Mathematical Operators |
Description |
+ |
Addition. For example: "#result = 2 + 3" Returns: 5 |
- |
Subtraction. For example: "#result = 2 – 3" Returns: -1 |
* |
Multiplication. For example: "#result = 2 * 3" Returns: 6 |
/ |
Division. For example: "#result = 2.0 / 3.0" Returns: 0.66666 |
% |
Modulus. For example: "#result = 3.0 % 2.0" Returns: 1 |
^ |
Exponent. For example: "result = 2 ^ 3" Returns: 8 |
Attribution and Variables |
Description |
= |
Used for attributions to a variable. For example: "#var = 5" |
#name |
Declares the name of a variable. For example: "#var = 'hello'" |
Ternary Operation (conditional operator) |
Description |
<Boolean expression> ? <if true then…? : <if false then…> |
Creates a condition to evaluate before executing an expression. For example: #var > 5 ? 'High' : 'Low' |
Functions and Mathematical Constants |
Description |
T(System.Math).E |
Returns established by the Math class of the .NET Framework 4.5. See: http://msdn.microsoft.com/en-us/library/system.math.aspx. |
T(System.Math).PI | |
T(System.Math).Abs(double value) | |
T(System.Math).Acos(double d) | |
T(System.Math).Asin(double d) | |
T(System.Math).Atan(double d) | |
T(System.Math).Atan2(double y, double x) | |
T(System.Math).BigMul(int a, int b) | |
T(System.Math).Ceiling(double a) | |
T(System.Math).Cos(double d) | |
T(System.Math).Cosh(double value) | |
T(System.Math).Exp(double d) | |
T(System.Math).Floor(double d) | |
T(System.Math).IEEERemainder(double x, double y) | |
T(System.Math).Log(double d) | |
T(System.Math).Log(double a, double newBase) | |
T(System.Math).Log10(double d) | |
T(System.Math).Max(double val1, double val2) | |
T(System.Math).Min(double val1, double val2) | |
T(System.Math).Pow(double x, double y) | |
T(System.Math).Round(double a) | |
T(System.Math).Round(double value, int digits) | |
T(System.Math).Sign(double value) | |
T(System.Math).Sin(double a) | |
T(System.Math).Sinh(double value) | |
T(System.Math).Sqrt(double d) | |
T(System.Math).Tan(double a) | |
T(System.Math).Tanh(double value) | |
T(System.Math).Truncate(double d) |
Auxiliary Functions |
Description |
#ToInt(value) |
Transforms the string or the decimal number specified into a whole number by approximation. |
#GetCulture(code) |
Transforms the regional code ("code") into a language culture format recognized by other conversion function (ex. ToString() ). The codes supported can be found in the following page: https://msdn.microsoft.com/en-us/goglobal/bb896001.aspx. |