Skip to main content

Logical expressions in messages

Description

The core of your highly personalized targeted messages are conditional expressions.

They are based on if → "then"→ else principles and can display different content depending on numerous conditions.

{if lead.field in json.promo_actions1}

You are free to use data variables both for conditions and for resulting alternatives. This can save really huge amounts of time when working with highly differentiated audiences.

As an example we'll take a situation where you need to set special discount options for one of your shop's VIP customers. It is also important that all other recipients get another discount offer, even if they are new to your company business.

  • Congratulations! Your premium discount is 42%! — for VIP customers of a specific shop
  • Special offer! Get a 20% discount for your second purchase! — for other recipients`

It's much faster to set 2 conditions within one message.

  1. The first condition checks if a customer has "best_buy_type" field, and if he is a customer of certain shop, if he is not, he receives usual suggestion.
  2. Next condition checks if any premium products have been purchased.
<!-- Condition 1: Are there any fields named "shop_name" and "best_buy_type" in customer's profile? -->
{if lead.shop_name and lead.best_buy_type}

<!-- Condition 2: Does the value for "shop_name" field match "my_shop"? -->
{if lead.shop_name equal "my_shop"}

<!-- Condition 3: Does the value for "best_buy_type" contain "premium"? -->
{if lead.best_buy_type contains "premium"}

<!-- All 3 conditions are met -->
<p>Congratulations! Your premium discount is 42%!</p>

<!-- Conditions 1 and 2 are met, no premium purchases made -->
{else}
<p>Special offer! Get a 20% discount for your second purchase!</p>
{end}
{end}

<!-- No conditions are met -->
{else}
<p>Special offer! Get a 20% discount for your second purchase!</p>
{end}

Examples

Conditions

Simple condition
{if "par1"}
if true
{else}
if false
{end}
Complex condition

Example 1:

{if "par1" in array["par1" "par2"] and ( 5 equal length("par 3") or false )}
if true
{else}
if false
{end}

Example 2 using apicontent:

{if apicontent.field_1 not_equal apicontent.field_2 and ( apicontent.field_1 or apicontent.field_2 )}
if true
{else}
if false
{end}

Example 3:

{if crypt("md5" lead._fname "salt") like "123b003aa39d110d1333b37af9889e10" and crypt("base58" lead.lottery_id) like json.crypted_winner}
if true
{else}
if false
{end}

Example 4:

{if iseven(lead.count) and iseven(lead.count2) equal false}
if true
{else}
if false
{end}
Check field and cancel sending if missing
{if lead.some_field}
some_field is not empty
{else}
{cancel}
{end}

Loops

Simple loop
{for array[1 "2" 3.3]}
{.}
{else}
if empty array
{end}
Loop with variables
{for $index, $el = array[1 "2" 3.3]}
{$index}: {$el}
{else}
if empty array
{end}

Value matching conditions

Equal
{if "par1" equal "par2"}
if true
{else}
if false
{end}
Not equal
{if "par1" not_equal "par2"}
if true
{else}
if false
{end}
String is equal (case insensitive)
{if "par1" like "par2"}
if true
{else}
if false
{end}
String is not equal (case insensitive)
{if "par1" not_like "par2"}
if true
{else}
if false
{end}
String contains (case insensitive)
{if "par1" contains "par2"}
if true
{else}
if false
{end}
String doesn't contain (case insensitive)
{if "par1" not_contains "par2"}
if true
{else}
if false
{end}

Numbers and dates comparison

More than number/date
{if 0 gt 1}
if true
{else}
if false
{end}
More than or equal to number/date
{if 0 gte 1}
if true
{else}
if false
{end}
Less than number/date
{if 0 lt 1}
if true
{else}
if false
{end}
Less than or equal to number/date
{if 0 lte 1}
if true
{else}
if false
{end}

Arrays and tags fields

Element is in array
{if "par1" in array["par1" "par2"]}
if true
{else}
if false
{end}
Element is in tags field
{if "tag1" in lead.TagsField}
if true
{else}
if false
{end}
Element is not in array
{if "par1" not_in array["par1" "par2"]}
if true
{else}
if false
{end}
Element is not in tags field
{if "tag1" not_in lead.TagsField}
if true
{else}
if false
{end}
All elements are in first array
{if array["par1" "par2"] all_in array["par1" "par2"]}
if true
{else}
if false
{end}
Not all elements are in first array
{if array["par1" "par2"] not_all_in array["par1" "par2"]}
if true
{else}
if false
{end}
At least one match in the arrays
{if array["par1" "par2"] any_of array["par1" "par2"]}
if true
{else}
if false
{end}
No matches in the arrays
{if array["par1" "par2"] not_any_of array["par1" "par2"]}
if true
{else}
if false
{end}