April 24, 2023

New formula in EspoCRM: if-then-else

EspoCRM has introduced a new feature in version 7.4 that includes if-then-else and while statements. This feature allows users to define conditional logic in formulas, which can be useful in various scenarios.

To use this feature, users can follow these simple steps:

  1. Open the Formula Editor in any entity where formulas can be used.
  2. Use the if-then-else statement to define a condition and its corresponding actions. The actions can be any valid formula expressions.
  3. Use the else-if and else statements to define additional conditions and actions, respectively.
  4. Use the while statement to define a loop that will execute the specified code block as long as the condition is true.
  5. Remember that braces are mandatory when using these statements.

This new feature is expected to provide greater flexibility and control to users when creating formulas in EspoCRM. Whether it’s a simple if-then-else statement or a complex loop, users can now use these statements to achieve their desired results.

Usage

if (CONDITION) {
    CODE
}
if (CONDITION) {
    CODE
} else {
    CODE
}
if (CONDITION) {
    CODE
} else if (CONDITION) {
    CODE
} else {
    CODE
}
while (CONDITION) {
    CODE
}

Examples

You can play with it in Formula Sandbox.

Code below will replace description in record if name is equal to Abc.

if (name == 'Abc') {
    description = '12345';
}
output\printLine(description);

Recent posts

Table of Contents

Unlock Your

25% Discount

Sign up and use code BLACKWEEK for an instant discount!
Click here to get more information.

Skip to content