Skip to main content

Hi there,

I’m trying to identify the necessary {{event.extra...}} parameter I need to enter in order to get a comma seperated list of all item IDs purchased?

 

I understand that I can use ‘{{ event.extra.Items.0.ProductId }}’ but this will only give me the first product ID ordered.

 

I need to get a list of all item IDs ordered and I’m struggling to work out the correct code to use for that?

 

Thanks in advance!

Hi @luke,

Thanks for sharing this with us.

There are two different ways of iterating over a given event variable arrays in emails:

  1. The Block Repeat Feature
    This feature allows you to add a single block (text, image, etc.) that will automatically repeat itself and iterate over all entries in a property array.
  2. A Dynamic Table
    This helps you create a more complex block that loops over all entries for a single variable array. 

While each of these methods have their own discrete help center articles, I also recommend checking out the event variables doc here.

In short, these methods follow the exact same principle. That is, taking the first “consistent” part of the tag, the part that holds true for all items in the array i.e. event.extra.Items in your case, assigning it an alias (which can be anything really) and then using the alias in a new dynamic tag to give us all of the results. 

So first we grab the “consistent” part of the tag that holds true for everything under ProductId, that is ‘event.extra.Items’ in your case, but it could be event.extra.line_items or something else. That portion is determined by the event data that the event provides us which can vary from event-to-event.

Then you assign an “alias” to this section. I like to think of the alias like a math equation, where the alias is the equivalent of “let X represent some algebraic expression” In this case, we’re saying, when we actually rewrite this tag to show us all of the results, we’ll let the alias represent the “consistent” part of the tag (event.extra.Items in the row collection or repeat for section) instead of using event.extra.Items. Here’s a few examples from each method:

 

Lastly, we insert the alias in place of the “row collection” or “repeat for” and remove the index in the array (the number portion the .0,.1.2 etc.) to complete the tag. So if your original tag looks like this: {{ event.extra.Items.0.ProductId }}. We insert the alias and remove the index to create the new tag which becomes {{ item.ProductId }}.

Then when you preview the email, you’ll see all of the results. I also recommend having a look through the articles I attached as they explain these concepts in slightly more depth!

I hope that is helpful!


Reply