Search
⌃K
Links

Set multiple conditional statements

if ... then ... else if | switch ... case
Create multiple conditional statements by concatenating if-then-else blocks. Write another if after else for another condition and so on—continue for as long as needed.

Example

As in the previous example, use the Total number field again and insert the following script into a Formula field:
1
if Total = null then
2
"Please enter an amount!"
3
else if Total >= 30 then
4
"Card" else "Cash" end
5
end
Result: In the function field you will receive the response "Cash", "Card" , or "Please enter an amount!" according to the input.
Replace multiple nested conditional statements with switch ... case. Use this statement to query an expression (switch ...) for possible results (case ...:) and set a default behavior (default:) if the expression does not correspond to any of the results.
Depending on the result, assign the next step accordingly. This helps avoid deeply nested if statements.
Tip: switch ... case works best when the queried value is a choice field.

Example

There's a choice field Payment method with the following options:
  1. 1.
    Cash
  2. 2.
    Bank transfer
  3. 3.
    Direct debit
Insert the following script into a formula field to display info about the selected payment type:
1
switch 'Payment method' do
2
case 1:
3
"Payment method: " + text('Payment method') + "."
4
case 2:
5
"Payment method: " + text('Payment method') + ". Only from €30."
6
case 3:
7
"Payment method: " + text('Payment method') + ". Do not forget your signature."
8
default:
9
"Please select a payment method."
10
end
Result: Based on your entry in the Payment method choice field, exactly one of the following info is visible in your formula field:
  • Payment method: Cash
  • Payment method: Bank transfer. Only from €30.
  • Payment method: Direct debit. Do not forget your signature.
  • Please select a payment method.
Do you want to dive deeper into the if ... then ... else topic? Take a look at the corresponding part of our video tutorial.
Do you want to dive deeper into the switch topic? Take a look at the corresponding part of our video tutorial.