Skip to content

Commit 3c87d75

Browse files
Merge pull request #474 from telerik/new-kb-nested-mailmerge-radwordsprocessing-d0b522c09f0c434bbcef2bb89b853381
Added new kb article nested-mailmerge-radwordsprocessing
2 parents ea122d5 + 2bcd0ea commit 3c87d75

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed
17.2 KB
Loading
11.4 KB
Loading
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
title: Performing Nested MailMerge with Multiple Levels in RadWordsProcessing
3+
description: Learn how to implement nested MailMerge operations with multiple levels of data, such as handling lists within lists, in RadWordsProcessing.
4+
type: how-to
5+
page_title: How to Handle Nested MailMerge with Multi-Level Data in RadWordsProcessing
6+
slug: nested-mailmerge-radwordsprocessing
7+
tags: wordsprocessing, mailmerge, nested, data, list, document, processing
8+
res_type: kb
9+
ticketid: 1668943
10+
---
11+
12+
## Environment
13+
14+
| Version | Product | Author |
15+
| --- | --- | ---- |
16+
| 2024.3.806| RadWordsProcessing |[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)|
17+
18+
## Description
19+
20+
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%}).
21+
22+
## Solution
23+
24+
To achieve a nested [MailMerge]({%slug radwordsprocessing-editing-mail-merge%} operation with multiple levels of data, follow the steps below:
25+
26+
1. Prepare your data model to reflect the nested structure. In this case, the model includes `Incident`, `Person`, and `Phone` classes.
27+
28+
2. 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.
29+
30+
3. Use special merge fields (`TableStart`, `TableEnd`, `RangeStart`, and `RangeEnd`) to denote the beginning and end of each nested collection.
31+
32+
Here is an example demonstrating how to set up your data model and perform the nested MailMerge:
33+
34+
```csharp
35+
// Define your data models
36+
public class Incident
37+
{
38+
public string ReportNumber { get; set; }
39+
public List<Person> People { get; set; }
40+
}
41+
42+
public class Person
43+
{
44+
public string FirstName { get; set; }
45+
public string LastName { get; set; }
46+
public List<Phone> Phones { get; set; }
47+
}
48+
49+
public class Phone
50+
{
51+
public string PhoneNumber { get; set; }
52+
}
53+
54+
// Preparing the data
55+
var mergeData = new List<Incident>{
56+
new Incident{
57+
ReportNumber = "INC-2024-001",
58+
People = new List<Person>{
59+
new Person{
60+
FirstName = "John",
61+
LastName = "Doe",
62+
Phones = new List<Phone>{
63+
new Phone{ PhoneNumber = "310-555-0101" },
64+
new Phone{ PhoneNumber = "310-555-0102" }
65+
}
66+
},
67+
// Add more Person instances as needed
68+
}
69+
}
70+
};
71+
72+
// Perform the MailMerge operation
73+
RadFlowDocument document = new RadFlowDocument();
74+
// Assume 'provider' is initialized and points to the appropriate document format provider
75+
var mailMergeResult = document.MailMerge(mergeData);
76+
```
77+
78+
In your document template, ensure you have the corresponding merge fields:
79+
80+
- For the start and end of the `People` list: `TableStart:People` and `TableEnd:People`.
81+
- For the start and end of the `Phones` list within each `Person`: `RangeStart:Phones` and `RangeEnd:Phones`.
82+
- For merging individual property values, use merge fields named after the properties, such as `FirstName`, `LastName`, and `PhoneNumber`.
83+
84+
![Nested mail merge template](images/nested-mail-merge-template.png)
85+
86+
### Generating the Necessary Table Structure in the Document
87+
88+
When dealing with nested collections, it's crucial to dynamically create table structures that can accommodate the varying lengths of these collections.
89+
90+
By following these steps and utilizing the provided code snippets, you can effectively perform nested MailMerge operations with multiple levels of data in RadWordsProcessing.
91+
92+
![Nested mail merge](images/nested-mail-merge-result.png)
93+
94+
## See Also
95+
96+
- [MailMerge]({%slug radwordsprocessing-editing-mail-merge%})
97+
- [Generating a Word Document with Data Using MailMerge in RadWordsProcessing]({%slug generate-doc-template-and-populate-with-collection-data-mail-merge%})
98+
- [Populate a Table with Data using Nested Mail Merge Functionality]({%slug populate-table-data-mail-merge%})

libraries/radwordsprocessing/editing/mail-merge.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,4 @@ If you want to separate the items into several rows you need to close the group
226226
* [Inserting Images using Mail Merge]({%slug inserting-images-using-mail-merge-radwordsprocessing%})
227227
* [Populate a Table with Data using Nested Mail Merge Functionality]({%slug populate-table-data-mail-merge%})
228228
* [Generating a Word Document Template with Data Using MailMerge in RadWordsProcessing]({%slug generate-doc-template-and-populate-with-collection-data-mail-merge%})
229+
* [Performing Nested MailMerge with Multiple Levels in RadWordsProcessing]({%slug nested-mailmerge-radwordsprocessing%})

0 commit comments

Comments
 (0)