Similarly to the article covering Numbered and Bulleted Lists; the Encodian population engine supports repeating sections/paragraphs, in fact, anything within a word document that could be repeated. The source JSON data must be in the form of an array, i.e. one or more items in the list.
Populate a repeating sections / paragraphs
Example Document: Encodian - Template Syntax - Repeats.docx
Example JSON Data:
{
"companyName": "Encodian",
"members": [
{
"listFirstName": "Efren",
"listLastName": "Gaskill",
"age": 45,
"homeTown": "Clearwater"
},
{
"listFirstName": "Sanly",
"listLastName": "Keyme",
"age": 19,
"homeTown": "Kensington"
},
{
"listFirstName": "Mark",
"listLastName": "Nigma",
"age": 36,
"homeTown": "Silver Spring"
}
]
}
Configure the document as required interlacing tokens within your actual content, for example:
<<foreach [member in members]>><<[member.listFirstName]>> <<[member.listLastName]>> is <<[member.age]>> years old and lives in <<[member.homeTown]>>.
<</foreach>>
This generates the following output:
Enabling null arrays/members
By default the 'Populate Word Document' actions 'Allow Missing Values' property is set to 'No' which will throw an error if a member has a null value, i.e. the following JSON will generate the following error:
{
"companyName": "Encodian",
"members": []
}
The complete error message: A general error occurred populating the word document provided: An error has been encountered at the end of expression 'member.listFirstName]>'. Can not get the value of member 'listFirstName' on type 'System.Data.DataRow'.
If elements of your JSON data could be null, then simply change the 'Allow Missing Values' property to 'Yes'
Checking for Null Arrays
The Any() method can be utilised to check whether an array member contains items or is null.
Example Document: Encodian - Template Syntax - Repeats - Null Array.docx
Example JSON Data:
{
"companyName": "Encodian",
"members": []
}
Configure the document as required using the Any() method to evaluate the array member, for example:
<<if [members.Any()]>>
<<foreach [member in members]>><<[member.listFirstName]>> <<[member.listLastName]>> is <<[member.age]>> years old and lives in <<[member.homeTown]>>.
<</foreach>>
<< else >>
no items
<< /if >>
This generates the following output:
0 Comments