Automation Action: If Block
Conditionally execute a one or more actions based on a Condition.
Conditionally executes a group of actions based on a Condition.
When you drag an If Action onto the actions list the Condition Builder will be displayed.
Here you create a Condition that will be tested. The condition must be true to start the If block otherwise processing moves to the next Else or End If statements.
In the If column you select a message variable or one of your Extracted Fields or Variables (you can also type text and have combinations of text and %variables%).
In the Is column you select one of the following Match Types:
- Equal To
- Not Equal To
- Less Than
- Greater Than
- Less Than Or Equal To
- Greater Than Or Equal To
- Is Blank
- Is Not Blank
- Contains One Of (list of words or phrases)
- Contains All Of (list of words or phrases)
- RegEx Matches (matches a regular expression)
- Does Not Contain
- Starts With
- Ends With (value
- Length Equal
- Length Less Than
- Length Greater Than
- Is A Valid Email Address (check the email address is the correct format)
- Is A Valid Email Address With MX Record (check the email address is the correct format AND has a valid MX record)
- Is Not A Valid Email Address
- Date Only Equal To
- Date Only Less Than
- Date Only Greater Than
- Hour Less Than
- Hour Greater Than
- Minute Less Than
- Minute Greater Than
- Weekday Number Equal To
In the Value column enter a value to compare against. This can contain %variable% replacements.
Click the Add button to add another line. The new line can be assigned as an AND or OR clause.
Each If statement must have a matching End If.
If blocks can be nested inside other If Blocks.
You can also assign a Condition to individual actions using the Condition tab of the Action properties page.
Contains / Does Not Contain Wildcards
The Contains and Does Not Contain match types can use wildcards in the value. For example: If value was 'good *,' - then this would match for a string containing 'Good Morning,' AND 'Good Afternoon,'. The Contains/Does Not Contain matches are case-insensitive.
|?||Any single character|
|*||Zero or more characters|
|#||Any single digit|
|[charlist]||Any single character in charlist|
|[!charlist]||Any single character not in charlist|
Contains One Of/Contains All Of Match Types
For the Contains One Of or Contains All Of match types you can enter multiple words or phrases. For Contains One Of the If field must contain at least one of the values. For Contains All Of it must contain all of the values. Both Contains One Of and Contains All Of use case-insensitive matching. Individual words/phrases can contain wildcards.
For example: Suppose we want to check that the message body (%Msg_Body%) contains 'Red' AND 'Blue' AND 'Green' - we would use Contains All Of and set the value to 'Red,Blue,Green'.
Individual words or phrases in the list can contain %variable% replacements. For example, you could use 'Red,Blue,%MyColor%' - %MyColor% will be replaced before the condition is checked.
By default the Contains One Of and Contains All Of match types match text anywhere, so if Contains One Of contained 'request' it would match for 'request' and 'requested' etc. To match whole words only, enclose the word or phrase in square brackets. For example: If we want to check that the message subject contains 'support' AND 'request' we would use Contains All Of and set the value to 'support,[request]'. This would match if the subject was 'New support request', but would NOT match if the subject was 'Support was requested'.
RegEx Matches Match Type
For RegEx Matches match type the value must be a valid Regular Expression. The match will be true if the If value contains one or more matches. For example: To check that the message body contains a ZIP code, set the If to
%Msg_Body% and use the RegEx Matches match type with the value set to
Comparing Numeric Values
If the If value and the value both contain numeric values then the Equal To, Not Equal To, Less Than, Greater Than, Less Than Or Equal To and Greater Than Or Equal To comparisons compare the numeric values rather than string literals. So '1000.00' and '1,000' would be evaluated as equal.
Comparing Date Values
Where the If value is a date or datetime (for example: %Msg_Date%), you can use:
- Date Only Equal To/Less Than/Greater Than : where value is also a date or datetime. Compares the date only portions (ignoring the time).
- Hour Greater Than/Less Than : where value is a number. Compares the hour value of the time.
- Minute Greater Than/Less Than: where value is a number. Compares the minute value of the time.
- Weekday Number Equal To : where value is a number. Compares the day of week value (0=Sunday,1=Monday..6=Saturday).
You can also use other match types (Equal To, Not Equal To, Greater Than etc) where the If value is a date/datetime and the value is a date/datetime. In these cases the dates are converted to yyyy-mm-dd hh:mm:ss format and then compared.
Example If Block
If %Msg_To% Contains support Then If %Msg_Subject% Contains One Of urgent,ticket Then // Support Email If %Msg_Date% Hour Greater Than 8 And %Msg_Date% Hour Less Than 18 Then // Day time Send Teams Message To Support Team "Support Request: %Msg_Subject%" For User Support Else // Out of hours Send Email To email@example.com "Support Email: %Msg_Subject%" End If End If End If