if($test, $then, $else)
$test ? $then : $else
Returns the result of the evaluation of then or else depending on the evaluation of test. If the evaluation of test is true, then then is evaluated and the result is returned, otherwise else.
All of the above notations are equivalent. Alternative notation: ifElse.
For case distinctions where multiple conditions must be evaluated, there is the alternative switch syntax. This avoids the nesting of conditions and leads to a much better readability in this case.
| Name | Type | Description | Mandatory | Default |
|---|---|---|---|---|
| test | Business object | An expression that returns true or false after evaluation. |
yes | |
| then | Business object | An expression that evaluates when test returns true . |
yes | |
| else | Business object | An expression that evaluates if test results in false. |
yes |
Type: Business object
The result of evaluating then or else, depending on the result of test.
{
time = dateTime(2021, 9, 13, 15, 24);
hour = $time.toSystemCalendar().hour();
($hour > 12).if("Nachmittag", "Vormittag")
}
Output: Nachmittag
The hour 13 is greater than 12, therefore the expression of "then" is output (note the time zone!).
{
x = 16;
($x >= 18)? "Here is your alcohol": "No alcohol vor kids!";
}
Output: No alcohol for kids!
Since x is less than 18, the result of else is returned.