MailMergeCleanupOptions.RemoveUnusedRegions causing issues with creating documents

Hi,
I am currently running in to an issue where I am having issues creating document with same table name in the template with MailMergeCleanupOptions.RemoveUnusedRegions setting added.
In the code below I have template named “testTemplate.docx” and when I run the code with MailMergeCleanupOptions.RemoveUnusedRegions setting only one table with same name gets populated. But when I remove that setting all tables with same name get populated.
The issue with removing MailMergeCleanupOptions.RemoveUnusedRegions settings is that tables that do not have data display template values which is not desirable.
Can you please let me know why this is the case and how this can be fixed without displaying template values.
I have attached outputs from that option selected and not selected. And link to the code is added too. Let me know if you need more information.
documents.zip (33.9 KB)

MailMerge.zip (274.7 KB)

@rasikaInsightly,

Please check if the following solution is acceptable for you?

DataTable productInfo = new DataTable("QuotationLineItem");

productInfo.Columns.Add("ProductName");
productInfo.Columns.Add("QUOTATION_DESCRIPTION");
productInfo.Columns.Add("Currency_Code");
productInfo.Columns.Add("Total_Price");

DataRow dr = productInfo.NewRow();
dr["ProductName"] = "product1";
dr["QUOTATION_DESCRIPTION"] = "5";
dr["Currency_Code"] = "$";
dr["Total_Price"] = "55";
productInfo.Rows.Add(dr);

dr = productInfo.NewRow();
dr["ProductName"] = "product2";
dr["QUOTATION_DESCRIPTION"] = "55";
dr["Currency_Code"] = "$";
dr["Total_Price"] = "66";
productInfo.Rows.Add(dr);

Document doc = new Document("E:\\Temp\\MailMerge\\testTemplate1.docx");

doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveUnusedFields | 
                               MailMergeCleanupOptions.RemoveEmptyTableRows |
                               MailMergeCleanupOptions.RemoveUnusedRegions;
doc.MailMerge.UseNonMergeFields = true;
doc.MailMerge.MergeDuplicateRegions = true;
doc.MailMerge.FieldMergingCallback = new HandleFieldMergingCallback();

doc.MailMerge.ExecuteWithRegions(productInfo);

doc.Save("E:\\Temp\\MailMerge\\19.11.docx"); 

I have just added doc.MailMerge.MergeDuplicateRegions = true; and taken out the doc.MailMerge.ExecuteWithRegions(productInfo); from inside the ‘for’ loop. Please check the “output_With_RemoveUnusedRegions_Option.docx” that is generated on our end by using the above code:

That worked!! Thank you so much.