Merge field with an "If statement"

Dear Support,
We are currently using Aspose to merge our word documents via XML as the
Data Source. It has been working well. This is the first letter we are trying
to merge where the word document has an “IF Statement” It doesn’t
appear to merge the data correctly.
I have attached the word document and also the XML data source.
The IF Statement is located in M20. M21 and M22.
Regards
Damien Farrugia
IT Operations Team Leader.
dfarrugia@visionsuper.com.au

Hi Damien,

Thanks for your inquiry.

I have worked with mail merge fields inside IF condition and have not found any issue while using latest version of Aspose.Words. In case you are using an older version of Aspose.Words, I would suggest you please upgrade to the latest version (v14.1.0) from here and let us know how it goes on your side.

If the problem still remains, please create a standalone/runnable simple application (for example a Console Application Project) that demonstrates the code you used to generate your output document and share it with us. I will investigate the issue and provide you more information.

Hi Tahir,
We’re currently using an older version of Aspose.Words for Java that supports Java version 1.6.0.24, which is a requirement for our document management system. We now need to update Aspose.Words to a version that supports if-statements. The updates we’ve seen seem to require a minimum of Java version 1.7. Could you please let me know what version of Aspose we can update to that supports if-statements as well as our version of Java?
We’ve tried Aspose version 14.1.0 to no avail. It doesn’t work at all with our system.
We use Weblogic, if that’s any help. Aspose is packaged into a .war file.
Thanks for your assistance.
Regards,
Damien

Hi Damien,

Thanks for your inquiry. I suggest you please upgrade to the latest version of Aspose.Words for Java 14.8.0. You can use aspose-words-14.8.0-jdk16.jar jar file with Java 1.6.

Aspose.Words
for Java is available for Java 1.4, 1.5, 1.6 and 1.7 and will run in
any place where Java is installed. Please read the system requirements
from here:
https://docs.aspose.com/words/java/system-requirements/

Hi Tahir,

Thanks for your suggestion. We’ve upgraded Aspose to the latest version. It’s successfully merging basic letters, but IF statements still don’t seem to work. I’ve uploaded our Word template and XML. Could you please take a look?

Thanks,

Damien

Hi Damien,

Thanks for your inquiry. I have tested the scenario and have not found the shared issue while using latest version of Aspose.Words for Java 14.8.0. Please use Aspose.Words for Java 14.8.0. If you still face problem, please share following detail for investigation purposes.

  • Please create a simple Java application that demonstrates the code (Aspose.Words code) you used to generate your output document

  • Please attach the output Word file that shows the undesired behavior.

Hi Tahir,
We are currently using version 14.8.0. When we merge the document all simple merge fields merge correctly, however the three IF statements pick up a number value from another merge field rather than displaying text, as the IF statement specifies for blank values.
Could you please attach the output that you receive when merging the XML? It would help to see your results and compare with ours.
Thanks for your help.
Damien

Hi Damien,

Thanks for your inquiry. I have tested the scenario using following code example and have not found the shared issue. I have attached the output document with this post for your kind reference. I suggest you please use latest version of Aspose.Words for Java 14.9.0. This issue does not exist in Aspose.Words v14.8.0.

Document doc = new Document(MyDir + "Letter-0115.doc");
String[] input_names = new String[]{"M20", "M21", "M22"};
Object[] input_data = new Object[]{"", "", ""};
doc.getMailMerge().execute(input_names, input_data);
doc.save(MyDir + "Out.doc");

Please let us know if you have any more queries.

Hi Tahir,
I appreciate your demonstration in merging an IF statement with Aspose with your VB Script though we are unable to use the xml data to generate the correct output for the IF Statement. Every other merge field works besides the IF statement. Are you able to simulate the merge process with the xml and template we supplied you for the Version of Aspose 14.8 for Java?

Hi Damien,

Thanks for your inquiry. We need following detail for investigation purpose. As soon as you get these pieces of information to us we’ll start our investigation into your issue.

  • Please create a simple Java application that demonstrates the code (Aspose.Words code) you used to generate your output document

  • Please attach the output Word file that shows the undesired behavior.

Hi Tahir, please see the attached. It’s the output we get when we try to merge the XML and Word letter template into our document management system. As you can see, the normal mergefields merge correctly, however the IF statements aren’t picked up at all.

Hi Tahir,

We have gotten to a point where the if statement is working though it is not updating the merge field.

I found the below query is this possibly to add into the Aspose merge process.

Java

Attached is the output file. If you look at M21 it has the value sitting behind the merge field though once we update the merge field it appears. Is there a way to update automatically.

Document doc = new Document(getMyDir() + "Rendering.doc");
// This updates all fields in the document.
doc.updateFields();
doc.save(getMyDir() + "Rendering.UpdateFields Out.pdf");

Damien

Hi Damien,

Thanks for your inquiry. There is no need to update fields after executing a mail merge because mail merge is a kind of field update and automatically updates all fields in the document.

I have tested again the same scenario using MailMerge.execute method and have not found the shared issue. Perhaps, you are using some different code. Could you please create simple Java application which you are using to generate the output document along with following detail? Unfortunately, it is difficult to say what the problem is without simplified application. We need your simple project to reproduce the problem.

  • What environment are you running on?
  • OS (Windows Version or Linux Version)
  • Architecture (32 / 64 bit)
  • Java version