Skip to content

Amazon Connect Message Templates — Unable to iterate array of objects from Customer Profiles using #each

0

I am using Amazon Connect Campaigns with Customer Profiles and Message Templates (Handlebars helpers). I need to display a list of add-ons in an email. Will be using these templates for Outbound Campaigns.

According to the documentation, the #each helper should work with arrays/lists.

Store an array of objects in a Customer Profile attribute:

"AddOnList": [ {"Add_on_Name__c": "Sunroof", "Add_on_Price__c": "1500"}, {"Add_on_Name__c": "Leather Seats", "Add_on_Price__c": "2000"} ]

Data is ingested using PutProfileObject with a custom Object Type.

Template used {{#each Attributes.Customer.Attributes.AddOnList}} {{this.Add_on_Name__c}} — ${{this.Add_on_Price__c}} {{else}} No add-ons selected {{/each}}

The loop runs, but object fields are empty. The Mail im getting contains No add-ons-selected

What works is: "AddOnList": [ "Sunroof — $1500", "Leather Seats — $2000" ]

{{#each Attributes.Customer.Attributes.AddOnList}} {{this}} {{/each}}

Printing all as one like [Sunroof - 1500, Leather Seats - 2000] just as a complete string

❓ Questions

Does Amazon Connect Message Templates support iterating arrays of objects from Customer Profiles?

Are Customer Profile attributes flattened to strings before template rendering?

Is there a supported way to pass structured list data (objects) to templates?

What is the recommended approach for rendering dynamic lists such as quotes, invoices, or add-ons?

1 Answer
0

Based on the behavior you're experiencing, Amazon Connect Message Templates have limitations when working with complex data structures from Customer Profiles. Here's what's happening and how to work with it:

Current Limitations:

Customer Profile attributes appear to be processed as strings rather than maintaining their complex object structure when passed to message templates. When you store an array of objects in a Customer Profile attribute, the template engine doesn't preserve the nested object properties, which is why {{this.Add_on_Name__c}} returns empty values.

What Works:

The #each helper does work with arrays, but it works best with simple arrays of primitive values (strings, numbers) rather than complex objects. This is why your second approach with pre-formatted strings like ["Sunroof — $1500", "Leather Seats — $2000"] works correctly - the helper can iterate over the array and access each string element using {{this}}.

Recommended Approaches:

  1. Pre-format your data: Store your list data as an array of pre-formatted strings in the Customer Profile attribute, as you discovered works. While this reduces flexibility, it's the most reliable approach given current limitations.

  2. Use Custom Attributes: When creating message templates, you can pass data through CustomAttributes (key-value pairs) rather than relying solely on Customer Profile attributes. This gives you more control over the data structure at template rendering time.

  3. Flatten complex data: If you need multiple pieces of information, consider storing them in separate arrays that maintain parallel indices, or create multiple simple attributes rather than one complex nested structure.

For Dynamic Lists:

For use cases like quotes, invoices, or add-ons, the most practical approach is to pre-process and format your data before storing it in Customer Profiles or passing it as custom attributes. Structure your data as simple arrays of formatted strings that can be reliably iterated using the #each helper with {{this}} to reference each element.

The template system is designed to work with flattened data structures rather than deeply nested objects, so data preparation and formatting before template rendering is key to achieving the desired output.
Sources
Use message template helpers - Amazon Connect
TemplateAttributes - Amazon Connect

answered 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.