Skip to main content

Custom Expression

2 minute read                                                                                                                 Intermediate


Splitting Responses based on Contact choices or Attribute values

There may be situations wherein a flow you would want to send different responses to different contacts based on their choices.

You can use the Split by a custom expression option to make that happen.

Split by a custom expression uses a coding syntax to match the response received or profile attribute.

The syntax will be like <%= if (Variable name == 'String' / number ), do: 1, else: 0 %>


Custom Expressions cheatsheet

  1. Get today's date in IST <%= Timex.today("Asia/Kolkata") |> Date.to_string() %>

  2. Get today's date and time in IST <%= DateTime.now!("Asia/Kolkata") |> DateTime.to_string() %>

  3. String concatenation function

    Put two variables in the results field in the update contact node. @results.Var1 @results.Var2

Screenshot 2023-08-30 at 12 26 12 PM

Syntax Examples

  1. Syntax to check if contact belongs to collection 1 or collection 2

<%= if "collection 1" in @contact.in_groups, do: 1, else: if "collection 2" in @contact.in_groups, do: 2, else: 3 %>

image

2 . Syntax to check if the contact is registered or not.

<%= if "@contact.fields.is_registered" == "1" , do: 1, else: 0 %>

3 . Syntax to check if the contact has opted-in or not.

<%= if @contact.optin_status == true, do: 1, else: 2%>

image

Any variable that is created and saved for contact can be used to make decisions in Split by custom expression syntax

To use Split by expression needs a bit of coding to write the correct syntax. If you have exact requirements for what needs to be done and needs assistance, please ping us on discord, we will share the correct syntax for the requirement.


Advanced Feature Webinar