if ... then ... else ... end
Use if ... then ... else ... end
to specify an if-then-else conditional statement that has Ninox check whether a sequence of statements should be executed (if... then...) or what should happen when the input condition is not met (... else...).
The if statement must be an expression that is either true
/yes or false
/no.
The use of comparison operators, such as greater than (>=
), less than (<=
) or equal to (=
) is also suitable for this purpose.
Depending on the result of the comparison, the further procedure is determined.
Create a Total field (number field type), type the following script in a formula field, and vary the value to Total:
Result: If the entered value in the Total field is greater than or equal to €30, payment is made by Card, otherwise payment is made in Cash.
You don't need to specify an alternative sequence, e.g., an else
. This means that a statement is either executed or not.
Result: paymentMethod
is set to Cash by default. However, if the value in the Total number field is greater than €30, the value for paymentMethod
is updated to Card.
Use null
to check whether a data field is empty. So null
does not stand for 0, but for empty. Combined with a branch, it allows you to execute a script even when a field is empty.
Result: If the Total field is empty, a prompt ("Please enter an amount!"
) is displayed.
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.
As in the previous example, use the Total number field again and insert the following script into a Formula field:
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.
There's a choice field Payment method with the following options:
Cash
Bank transfer
Direct debit
Insert the following script into a formula field to display info about the selected payment type:
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.