Dynamic lookup values

When using Datatable fields it can be useful to simply pull in a single product no matter who the recipient is, but it is more likely that the product we want to put into our email will be based on some other factor.

For our example we will assume we would like to send a follow-up email to our customer one month after they make a purchase. In this email, we would like to include the name of the product they bought and invite them to submit a review. We can do this by using a dynamic value in our lookup field rather than setting a fixed value. We would like the lookup value to be equal to the ID of the product they last purchased.

We will need to make sure that we have:

The Format

Taking the example we had before:

[datatable(lookup=1):Sports Online/products.name;A Great Product]

We just want to replace the static 1 for a value in the customer data that lists their previously purchased product.
Wrapping that data within % signs will allow us to use it as a dynamic lookup value.
So our code example will then look like this:

[datatable(lookup=%recipient:retail.last purchased product%):Sports Online/products.name;A Great Product]

The Steps

Let's assume the following profile field setup:

To add the value from the recipient's last purchased product profile field we can take the following steps:

  1. Add the Datatable product code to our email following the steps from the Using Datatable fields lesson
  2. With the value of the lookup highlighted click on the Insert Profile Field icon
  3. In the resulting popup dialogue box we can then select the profile field that we want
  4. On clicking OK we see the code inserted will now look like this

[datatable(lookup=[recipient:retail.last purchased product]):Sports Online/products.name]

  1. Finally, we just need to remove those square brackets either side of the inserted profile field text and replace them with our percentage signs.

Our updated lookup value will then be:

[datatable(lookup=%recipient:retail.last purchased product%):Sports Online/products.name;A Great Product]

Our email will now dynamically display the name of a different product per customer based on what they last purchased.