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:
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.
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.twitter etc. Now those are found in
@urns, for example:
Your phone number is @urns.tel and your twitter handle is @urns.twitter.
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
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
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
@input.textetc representing the last message received from the contact.
- Date values like
@date.nowbecome function calls
- The boolean not equal operator
<>becomes the more recognizable
- A new
defaultfunction makes it easier to deal with missing values, e.g.