Struggling with Mail Merge (using object dot notation)

Hi!
I have a template that has two merge fields for example:

Branch1.Name and Branch1.Phone

When I run it like this

string[] fieldNames = new string[] { "Branch1.Name", "Branch1.Phone" };
string[] fieldValues = new string[] { "Test", "+49 123456" };
//Performs the mail merge
document.MailMerge.Execute(fieldNames, fieldValues);


everything works as expected. If I try this:


var test = new Branches
{
Branch1 = new Branch
{
Name = "Branch Name",
Number = "+49 123456"
}
};
var myList = new List<Branches> { test }.AsEnumerable();
document.MailMerge.Execute(myList);


it doesn't work. 

The fields are correct if I check in

var mm = document.MailMerge.GetMergeFieldNames();


What am I doing wrong?


1 Reply

AA Akash Arul Syncfusion Team December 11, 2023 12:33 PM UTC

Hi Paul,

On analyzing the given details, we found that the property name given in the class (Name and Number) and the name in the template Word document (Branch1.Name and Branch1.Phone) is different. And the class Branches has a nested class Branch which is not necessary. This leads to the issue.

Mail merge is a process of merging data from data source to a Word template document. The Mail merge operation replaces the matching merge fields with the respective data.
To know more about simple mail merge, please refer to the below UG documentation.
https://help.syncfusion.com/file-formats/docio/mail-merge/simple-mail-merge

To achieve your requirement, it is important that the field name in the template Word document and the property name in the class should be the same.

Refer to the below GitHub sample for your requirement.
https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Mail-Merge/Create-Envelopes-for-mailing

We have prepared a sample for your requirement and attached it here. Please take a look at it.
Note: Please find the template Word document in the attached zip.

The nested class will be created for Nested group mail merge.
Refer to the below UG documentation to know about Nested group mail merge.
https://help.syncfusion.com/file-formats/docio/mail-merge/mail-merge-for-nested-groups

Regards,
Akash.


Attachment: WordToPDFCore_2477a984.zip

Loader.
Up arrow icon