Merging Nested Repeating Blocks
Thanks to the data source excerpt file concept, it is very easy to create templates with complex structures such as nested repeating blocks. A data source excerpt file is used to fill the drop-down lists of the template editor with proper merge fields, relations and dummy data for a template preview. A data source excerpt file is not the actual data that is used to merge the template. It helps to design the templates and to insert the proper field names.
In this article, the following .NET classes are used as the data source structure for the ReportingCloud merge process:
Report is the master template which reflects the complete template. In other words, the complete template is merged with the number of rows in this master template. The following code shows the instantiated .NET object that is used:
This object has 1 Sale object which consists of 2 different Item objects. In the template, a list of all Sale items should be visualized as a merge block. Inside this outer merge block, all Item objects should get listed as a nested merge block. The following screenshot shows this structure in the template:
Adding the Data Excerpt File
But how to insert these blocks in the ReportingCloud template designer?
-
First, we need to create a serialized JSON string from the object. You can create this string manually or simply serialize this object using the JavaScriptSerializer class:
-
The results will look similar to this:
-
In the ReportingCloud Portal, open My Datasource Excerpts and create a new excerpt file by adding a name and pasting the JSON string to the excerpt input. As ReportingCloud expects an array of objects as the data source, enclose the complete string with square brackets.
Designing the Template
Now, when designing the template in the ReportingCloud template designer, the merge blocks are listed in the available Insert Merge Block drop-down button. In the ReportingCloud Portal, create a new template in the My Templates area. Before editing the template, select the created datasource excerpt file from the available sources and confirm with Edit Template.
-
In the opened template designer, click on sales from the Insert Merge Block drop-down to insert the outer merge block sales.
-
Set the input position into the block row and add a table row using the right-click context menu.
-
Set the input position into the newly created table row and choose items from the Insert Merge Block drop-down to insert the nested block items.
-
In the opened dialog, select the 2 columns price and qty and confirm with OK.
A second nested block has been inserted into the outer block:
When previewing this template, the expected results of the nested block are rendered successfully: