IF Action
The "If" plugin in Tracardi is a conditional action that allows you to selectively run a branch of the workflow based on a specified condition. This plugin evaluates the provided condition and returns the payload on the "true" port if the condition is met, or on the "false" port if the condition is not met.
Plugin Configuration
The behavior of the "If" plugin is determined by the following configuration options:
-
Condition statement: This configuration option allows you to provide a condition for the IF statement. If the condition is met, the payload will be returned on the "true" port; otherwise, the "false" port will be triggered.
-
Return value only once per condition change: By enabling this option, the relevant port will be triggered only once per condition change. If the option is disabled, the flow will be stopped.
-
Expire trigger again after: If the value is set to 0, the event will occur only once and will not be triggered again unless the conditions change. However, if a value greater than 0 is set, the event will be triggered again after the specified number of seconds, regardless of whether the conditions have changed or not.
-
Return input payload instead of True/False: Enabling this option will return the input payload on the output ports if it is enabled; otherwise, True/False will be returned.
Plugin Outputs
The "If" plugin has two output ports:
-
true: If the defined condition is met, the payload will be returned on this port.
-
false: If the defined condition is not met, the payload will be returned on this port.
Condition syntax
This node uses a language very similar to SQL conditionals. It also uses dotted path notation to access the data. All fields must contain a source and a path to value e.g:
This means the value traits.public.pii.name from profile will be used in the conditional statement.
Language grammar
The following grammar rules define expression syntax in [If node].
that means that expressions with similar operators e.g. OR must be in brackets. The following conditional statement is forbidden:
correct statement is either:
or
There is no auto resolution of priority operations
Condition resolution
Each condition consist of a field, operator, and value. An operator is used to manipulate individual data items and return a result. Operators are represented by special characters or by keywords. List of operators is available below.
Example
This example will trigger True port on the [IF node] if numberOfPurchases in payload equals 1
Operations can be joined by AND/OR.
Example
This example will trigger True port on the [IF node] if numberOfPurchases in payload equals 1and title in payload equals "Title".
There are other operators possible like:
- less then (<)
- greater then (>)
- less or equal then (<=)
- greater or equal then (>=)
- not equal (!=)
- exists (fieldname EXISTS)
- not exists (fieldname NOT EXISTS)
Value types
In the example:
Field payload@numberOfPurchases is considered an integer number while payload@title is considered a string.
Examples
-
Simple Comparison:
-
AND/OR Conditions:
-
BETWEEN Condition:
-
IS NULL/IS NOT NULL Conditions:
-
EXISTS/NOT EXISTS Conditions:
-
EMPTY/NOT EMPTY Conditions:
-
CONTAINS Condition (contains string):
-
STARTS WITH/ENDS WITH String Conditions:
-
Array Conditions:
Warning
Please note that the examples provided above are just illustrations of how the conditions might look like within the given syntax. The actual conditions used will depend on the specific context and data structure being used.
Troubleshooting
When you compare date you must pay attention to dates types. There are dates that are time zone aware (offset-aware) and dates that are not aware of time zone. You can not compare them.
Time functions
The following time functions are available:
- now()
- utcnow()
- datetime("
"), e.g datetime("2021-01-01 00:00:00") - datetime(
), e.g datetime(profile@metadata.time.insert) - now("
"), e.g. now("europe/warsaw") - now.offset("europe/warsaw", "+700 days")
- now.offset(payload@time, "+700 days")