title | description | type | page_title | slug | tags | res_type | ticketid |
---|---|---|---|---|---|---|---|
Performing Nested MailMerge with Multiple Levels in RadWordsProcessing |
Learn how to implement nested MailMerge operations with multiple levels of data, such as handling lists within lists, in RadWordsProcessing. |
how-to |
How to Handle Nested MailMerge with Multi-Level Data in RadWordsProcessing |
nested-mailmerge-radwordsprocessing |
wordsprocessing, mailmerge, nested, data, list, document, processing |
kb |
1668943 |
Version | Product | Author |
---|---|---|
2024.3.806 | RadWordsProcessing | Desislava Yordanova |
Learn how to perform a [MailMerge]({%slug radwordsprocessing-editing-mail-merge%}) operation with multiple levels of nested data, such as a list within a list (e.g., Incident
> Person
> Phones
) in [RadWordsProcessing]({%slug radwordsprocessing-overview%}).
To achieve a nested [MailMerge]({%slug radwordsprocessing-editing-mail-merge%} operation with multiple levels of data, follow the steps below:
-
Prepare your data model to reflect the nested structure. In this case, the model includes
Incident
,Person
, andPhone
classes. -
Use the [MailMerge]({%slug radwordsprocessing-editing-mail-merge%}) method to merge the data with the document template. Ensure your document template has the appropriate merge fields defined for each level of data.
-
Use special merge fields (
TableStart
,TableEnd
,RangeStart
, andRangeEnd
) to denote the beginning and end of each nested collection.
Here is an example demonstrating how to set up your data model and perform the nested MailMerge:
// Define your data models
public class Incident
{
public string ReportNumber { get; set; }
public List<Person> People { get; set; }
}
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public List<Phone> Phones { get; set; }
}
public class Phone
{
public string PhoneNumber { get; set; }
}
// Preparing the data
var mergeData = new List<Incident>{
new Incident{
ReportNumber = "INC-2024-001",
People = new List<Person>{
new Person{
FirstName = "John",
LastName = "Doe",
Phones = new List<Phone>{
new Phone{ PhoneNumber = "310-555-0101" },
new Phone{ PhoneNumber = "310-555-0102" }
}
},
// Add more Person instances as needed
}
}
};
// Perform the MailMerge operation
RadFlowDocument document = new RadFlowDocument();
// Assume 'provider' is initialized and points to the appropriate document format provider
var mailMergeResult = document.MailMerge(mergeData);
In your document template, ensure you have the corresponding merge fields:
- For the start and end of the
People
list:TableStart:People
andTableEnd:People
. - For the start and end of the
Phones
list within eachPerson
:RangeStart:Phones
andRangeEnd:Phones
. - For merging individual property values, use merge fields named after the properties, such as
FirstName
,LastName
, andPhoneNumber
.
When dealing with nested collections, it's crucial to dynamically create table structures that can accommodate the varying lengths of these collections.
By following these steps and utilizing the provided code snippets, you can effectively perform nested MailMerge operations with multiple levels of data in RadWordsProcessing.
- [MailMerge]({%slug radwordsprocessing-editing-mail-merge%})
- [Generating a Word Document with Data Using MailMerge in RadWordsProcessing]({%slug generate-doc-template-and-populate-with-collection-data-mail-merge%})
- [Populate a Table with Data using Nested Mail Merge Functionality]({%slug populate-table-data-mail-merge%})