Expression changes in the new editor
You've always been able to use expressions in your flows to customize messages and make more complex splits. With the new editor we're also introducing some changes to expressions which will make them more powerful and easier to work with.
The basic syntax remains the same. For example to include the contact's name in a message action you still use:
And if you want to do something more complex like a function call:
There is a reference guide for new editor expressions, and this article is just covering some of the most important differences.
Previously If you had custom field (let's say Age), you would have accessed it like @contact.age. Now if you want to access the value stored for that field for the current contact, you use:
Or as a shorthand..
Likewise if you want to access URN of particular types, you would have previously used @contact.tel and @contact.twitter etc. Now those are found in @urns, for example:
Previously if you created a split with a label (let's say Gender), you would have accessed the result later on in your flow like @flow.gender . Those results are now found in @run.results, for example:
Or as a shorthand..
If you want the category in the contact's language, use @results.gender.category_localized instead.
Previously the response of webhook call was parsed as JSON and saved to @extra and subsequent calls would overwrite each others responses. Now each response gets its own little extra which you can access using the result name. For example if you have a webhook action with a result name like Address Lookup, then you can find the response parsed as JSON at..
For convenience you can access the response of last webhook call made at @webhook, e.g.
Previously you could add days to a date using + or months using the cryptically named EDATE() function. New expressions have access to several new functions which should make date manipulation much simpler.
datetime_add allows you to add seconds, minutes, hours, days, months or years to a given date. For example:
@(datetime_add("2017-01-15", 5, "D")) adds 5 days
@(datetime_add(fields.dob, -3, "M")) subtracts 3 months
replace_time allows you to replace the time component of any datetime. For example:
@(replace_time(now(), "10:30")) returns today at 10:30am.
Previously if you started a run from an API call, you could provide a JSON blob which would then be accessible in the flow as @extra . You can now find that at @trigger.params .
@step.value becomes @input.text etc representing the last message received from the contact.
Date values like @date.today and @date.now become function calls @(today()) and @(now()) .
The boolean not equal operator <> becomes the more recognizable !=
A new default function makes it easier to deal with missing values, e.g. @(default(contact.age, 18))
The basic syntax remains the same. For example to include the contact's name in a message action you still use:
Hi there @contact.name
And if you want to do something more complex like a function call:
HI THERE @(upper(contact.name))
There is a reference guide for new editor expressions, and this article is just covering some of the most important differences.
The Contact
Previously If you had custom field (let's say Age), you would have accessed it like @contact.age. Now if you want to access the value stored for that field for the current contact, you use:
You are @contact.fields.age years old
Or as a shorthand..
You are @fields.age years old
Likewise if you want to access URN of particular types, you would have previously used @contact.tel and @contact.twitter etc. Now those are found in @urns, for example:
Your phone number is @urns.tel and your twitter handle is @urns.twitter.
Results
Previously if you created a split with a label (let's say Gender), you would have accessed the result later on in your flow like @flow.gender . Those results are now found in @run.results, for example:
You said @run.results.gender which is @run.results.gender.category
Or as a shorthand..
You said @results.gender which is @results.gender.category
If you want the category in the contact's language, use @results.gender.category_localized instead.
Webhooks
Previously the response of webhook call was parsed as JSON and saved to @extra and subsequent calls would overwrite each others responses. Now each response gets its own little extra which you can access using the result name. For example if you have a webhook action with a result name like Address Lookup, then you can find the response parsed as JSON at..
@run.results.address_lookup.extra@run.results.address_lookup.extra.zip_code
For convenience you can access the response of last webhook call made at @webhook, e.g.
@webhook@webhook.zip_code
Date Manipulation
Previously you could add days to a date using + or months using the cryptically named EDATE() function. New expressions have access to several new functions which should make date manipulation much simpler.
datetime_add allows you to add seconds, minutes, hours, days, months or years to a given date. For example:
@(datetime_add("2017-01-15", 5, "D")) adds 5 days
@(datetime_add(fields.dob, -3, "M")) subtracts 3 months
replace_time allows you to replace the time component of any datetime. For example:
@(replace_time(now(), "10:30")) returns today at 10:30am.
Runs started from the API
Previously if you started a run from an API call, you could provide a JSON blob which would then be accessible in the flow as @extra . You can now find that at @trigger.params .
Miscellaneous Changes
@step.value becomes @input.text etc representing the last message received from the contact.
Date values like @date.today and @date.now become function calls @(today()) and @(now()) .
The boolean not equal operator <> becomes the more recognizable !=
A new default function makes it easier to deal with missing values, e.g. @(default(contact.age, 18))
Updated on: 13/12/2021
Thank you!