Logic
Mar 03, 2023 • 4 minutes to readThe elements of logic include conditional and comparison blocks used to modify trigger behavior. The following blocks are available: IF…THEN… , CASE, true/false, AND/OR, NOT, not true/false, and comparison blocks.
IF… THEN…
IF… THEN… statement can be used to conditionally execute the logic based on the status of a condition. If the condition is true, the statement is executed, and if the condition is false, then the IF statement does nothing.
It can be used to conditionally send email reminders to sales representatives based on the status of their open leads.
Options
You can combine IF… THEN… with ELSE. To do so, click the gear icon in the block.
IF… THEN… executes actions defined in ELSE when the IF condition is not satisfied.
In the above example, whenever the condition is true, the record with the matching ID is removed from the table. Otherwise, an email with a notification is sent.
Note: The IF… THEN… block is resource-hungry, which means it may slow down your application. Therefore, it is preferable to move the condition from the IF… THEN… to the WHERE block whenever possible.
CASE
CASE reads all the conditions and returns a value when the first condition is met. When the first condition set to true is encountered, it stops reading and returns the result.
For example, it can be used to define conditions upon which field categories are assigned to a given table. The CASE function reads the conditions and, when the first true condition is encountered, assigns the corresponding category to the field.
Options
You can combine CASE with ELSE. To do so, click the gear icon in the block.
CASE returns the value in the ELSE clause when no conditions in the logic are true. If there is no ELSE option and no true conditions, it doesn’t return any value.
Note: A CASE block should always return one and the same data type. Returning different data types, for instance, number in WHEN but text in ELSE can lead to undefined behavior and incorrect trigger operation.
True/False
True/False provides true or false value for a statement. It can be used in the logic statements.
AND/OR
And/ Or elements can be combined with WHERE or when joining tables.
For And, the condition is true if all the conditions separated by And are true.
For Or, the condition is true if any of the conditions separated by Or is true.
NOT
Displays a record if the condition is not true. It is used to negate a condition in the WHERE block.
Not True/False
Not True/False returns inverted true/false value.
Comparison blocks
Comparison blocks check whether two expressions in the condition are the same. They operate upon the following comparison operators:
- equal
- not equal
- less than
- less than or equal
- greater than
- greater than or equal
- is blank/ is not blank – returns true if the given value is empty. 0 value for the numeric field is considered a value, so it returns false for the comparison “is empty”.
- is number/ is not number – returns true if the given string is numeric. It allows for “-” symbol, whitespaces, decimal separators, exponential format (3e8), etc.
- Contains/ does not contain – returns true if the string from the left has an occurrence of the sub-string from the right. It doesn’t require wildcards (%).
- In/ not in – returns true if the given value from the left side exists in the set of values from the right side in the block (exact match). This comparison can only work with the list or SELECT blocks in the right part. If the SELECT block is used, it is restricted to a single field.
- Between/ not between – returns true if the argument from the left side is between the range of two values from the right side. The values can be numbers, text, or dates. This comparison type is inclusive working as a shortcut for the pair “val less or equal B AND greater or equal A”. In the right part, the first value must be less than the second value. When between/not between is used with the text values, it compares them symbol-by-symbol starting from the first one (case sensitive comparison).
- Exists/ not exists – returns true if the provided SELECT query returns at least one record. It works with the SELECT block only.