- Home
- Forum
- ASP.NET MVC - EJ 2
- Conditional sections (if/else) in mail merge
Conditional sections (if/else) in mail merge
Thank you for contacting Syncfusion support.
To meet your requirement, we suggest you BeforeClearFieldEventHandler to set the field value if the field value is empty or null for the field. We have prepared a sample application for the same and it can be downloaded from the below link:
https://www.syncfusion.com/downloads/support/forum/147391/ze/GenerateWord603663313
Note: Please find the input Word document in the “Data” folder of above sample application.
Please refer the below UG documentation link to know more about working with mail merge events in Word document using DocIO:
https://help.syncfusion.com/file-formats/docio/working-with-mailmerge?cs-save-lang=1&cs-lang=csharp#beforeclearfield-event
If we misunderstood any of your requirement, kindly provide us your input Word document along with modified code snippet of above sample application and provide details about your complete end requirement, thereby we will analyze the feasibility further on the mentioned requirement and update you with the appropriate solution at the earliest.
Please let us know if you have any other questions.
Regards,
Poorani Rajendran
Attachment: GenerateWordIfElse_eacf849e.zip
Thank you for your update.
To meet your requirement, we suggest you set the merge field (“<<ThereAreUsers>>”) within the IF field in the template Word document and it will be updated based on the merge field result. To update the fields in Word document, we suggest you use UpdateDocumentFields API. Please find the below Microsoft Word application screenshot to insert the merge field within the IF field (Right click on the Field, select Toggle Field Codes or ALT+F9 shortcut key).
In the given sample, we have found that you are setting ClearFields property as false to preserve the unmerged fields as it is in the Word document. We have found that you are executing mail merge for Word document using Execute API(“<<FirstName>>”) as first execution. It performs mail merge with all the fields in the Word document and preserved the unmatched fields based on ClearFields property.
In your case, if there is no value for merge field (“ThereAreUsers”) within IF field, then merge field preserved as unmerged field. This will be reflected in updating IF field expression. So, we suggest you set ClearFields property as true and also recommend to perform ExecuteGroup as first execution before calling Execute API. Thereby, mail merge is executed for particular group in first time execution and then executed for remaining merge fields in whole Word document (fields without any group). We have modified the given sample application to achieve your requirement and it can be downloaded from the below link:
https://www.syncfusion.com/downloads/support/forum/147391/ze/GenerateWordIfElse1484679146
Please let us know if you have any other questions.
Regards,
Poorani Rajendran.
Is there a way to insert a conditional merge field inside the document editor ?
I'm already able to insert a merge field at the cursor position like so :
Thanks
Is there any update on this request?
Hi Sumanth,
As mentioned, we usually have an interval of at least three months between the releases. At the planning stage for every release cycle, we review all open features once again and finalize features for implementation based on specific parameters including product vision, technological feasibility, and customer interest. We will let you know when this feature is implemented.
You can track the status of feature from the below link:
https://www.syncfusion.com/feedback/8477/add-support-to-insert-and-edit-custom-fields
Regards,
Selvaprakash K
Sumanth, You can communicate with us or track the status of the feature using the below feedback link.
Feedback Link: https://www.syncfusion.com/feedback/8477/add-support-to-insert-and-edit-custom-fields
- 8 Replies
- 7 Participants
-
TJ Tomasz Jagusz
- Sep 9, 2019 11:18 AM UTC
- May 17, 2023 05:10 AM UTC