Repeating data in tables
For email and document communications, you can include repeating data within tables. For example, you may want to create a table that has 100 rows, each for a different order, specifying such things as order description, price and quantity. EngageOne™ Communicate allows you to create a single row with the appropriate references to data arrays, then when you preview or send the email or document, the table will be filled out with as many rows as there are in the arrays.
To do this, you must first create a JSON or XML file to define the data arrays (an Excel spreadsheet cannot be used). An example of a JSON file that defines two arrays is given below:
[
{
"firstname": "John",
"lastname": "Smith",
"email": "john.smith@mycompany.com",
"order_number": "5555",
"delivery_address": [
"Appartment 234",
"High Road North",
"Some Town"
],
"order_items": [
{
"description":"Complete Puppy Food",
"price":"3.49",
"qty":"2",
"total":"6.98"
},
{
"description":"Chunky Dog Treats",
"price":"0.99",
"qty":"5",
"total":"4.95"
}
],
"subtotal": "27.55",
"salestax": "6.88",
"total": "34.43",
"est_del_date":"September 12 2019"
}
]
delivery_address
is an example of a string array. EngageOne™ Communicate imports the key of the array as an array. This means that in the metadata generated for the JSON data, the key of that array is marked as array.order_items
is an example of an object array. EngageOne™ Communicate imports the key of the array as an array, For all the fields for the JSON objects inside the array, the keys are marked as either string or array, as appropriate.
To create a table with repeating data:
- Add a table to the communication (see Tables).
- Import the JSON or XML file that defines the arrays as a Data Source (see Data Sources).
- Insert text blocks into the cells of the row that you want to repeat.
- Hold the mouse above the row and click Edit row. The following is displayed at the right side:
- Click the button to the right of Repeat this row with data to
turn this option on. A dropdown is displayed that shows the arrays in the data
source:
- Select one of these arrays, for example, order_items.
- Select the first cell in the row, and click Add personalization. This will now have a menu option order_items >. If you click this, a list of all data items in the array is shown:
- From this menu, select the option required for the selected cell (description,
price, qty or total). Repeat for the other cells. The table will look like
this:
- The symbol id="image_ltv_2sh_bpb" indicates that the table contains a repeating row.
- When you preview or send the email or document, it looks like this: There are two rows because in the original JSON file, the array order_items has two entries.
- Arrays of plain strings
- Arrays of plain numbers
- Arrays of objects
- Arrays of arrays of objects.
You can have up to ten levels of nested repeating data.