Unconditionally Populate Merge Fields & Mail Merge Regions in IF Fields of Word Document using Java

Hello,
we have upgraded Words.jdk16 - from 15.05 to 20.12 recently and some documents have problems when generated to PDF

I have attached simplified template which we have and result in docx where can be seen value NEWREQDATELETTER is not properly shown. We believe mergefield in if statement is not properly evaluated. Then later on in the conversion they are evaluated to true, but the data is no longer available to replace the merge field. Placeholder variable to hold the value of the merge field outside of the conditional fixed the problem.

We would like to ask you what changed or what we do wrong/ need to change in order to make it work. We would like to have some workaround instead of changing it in every template.
Thank you

.Examples.zip (83.6 KB)

@jcash_casenetllc_com,

Please upgrade to the latest (21.3) version of Aspose.Words for Java and see how it goes on your end? In case the problem still remains, then please ZIP and upload the following resources here for testing:

  • Aspose.Words for Java 21.3 generated output DOCX file showing the undesired behavior
  • Your expected DOCX file showing the desired output. You can create this document by using old 15.5 version of Aspose.Words for Java.
  • Please also create a standalone simplified Java Application (source code without compilation errors) that helps us to reproduce your current problem on our end and attach it here for testing. Please do not include Aspose.Words JAR files in it to reduce the ZIP file size.

As soon as you get these pieces of information ready, we will start further investigation into your issues and provide you more information.

@awais.hafeez
I have created two projects with related versions which generates PDFs as we do it in our app. The data, template and steps are same. Both using minimalTemplate.docx which is in zip and must be placed in temp folder.
AsposeExample15.05
AsposeExample20.12\

Each generate output2012Result.pdf and output1505Result.pdf . In template is this sequence
image.png (10.8 KB)

version 15.05 show both values
image.png (3.4 KB)

version 20.12 show just one
image.png (4.2 KB)

We have many templates which have same/similar structure and we would like to avoid correcting all templates. Thank you

aspose projects.zip (62.4 KB)

@jcash_casenetllc_com,

Please upgrade to the latest (21.3) version of Aspose.Words for Java and set value of MailMerge.UnconditionalMergeFieldsAndRegions property to true.

...
...
MailMerge mailMerge = doc.getMailMerge();
mailMerge.setUnconditionalMergeFieldsAndRegions(true);
mailMerge.execute(empty.toArray(new String[0]), empty.toArray());
doc.updateFields();
...
...

Thank you @awais.hafeez , setting flag helped. We run into another issue.
When bookmark is not set properly for the first time. If I remove IF statement in SET INDVLINE, it start to work.

Also if I open docx file, select all and hit F9, it shows correct results. Like it does not show the latest state.

I have created two projects for both versions again
AsposeExample15.05
AsposeExample20.12
Both using minimalTemplateService.docx which is in zip and must be placed in temp folder.
aspose project services.zip (62.7 KB)

Each generate output2012Result.pdf and output1505Result.pdf .

version 15.05 show all 3 values
image.png (1.8 KB)

version 20.12 ommits first one but following are present
image.png (2.4 KB)

Thank you

@jcash_casenetllc_com,

After an initial test with the licensed latest (21.3) version of Aspose.Words for Java, we were unable to reproduce this issue on our end. Please see the following output DOCX and PDF files which were generated on our end:

So, the issue with 20.12 version is now fixed and we suggest you to please upgrade to the latest 21.3 version of Aspose.Words for Java.