Document.updateFields() wrong field values in tables

Hello,

I have the following issue with Aspose and kindly request your assistance:

Error Description

Library: The error occurs with “Aspose-Word for Java”, version 17.4 as well as 20.3.

Summary: There seems to be an issue with the Aspose-method “Document.updateFields()” if those fields are within a table that is in a field. Word itself handles this correctly on a manual refresh (select everything with CTRL + A and press F9).

More details: I have a SET-field in Word with a certain name. This field is embedded in a table. This table is part of another (otherwise blank) field. After this block I check if the assigned field value is correct (REF field). This whole setup is repeated another time (with the same field name, but different SET field value). If I now use the Aspose-method “Document.updateFields()”, each instance of the field will have the same value assigned to it. More specifically, it always uses the last value assigned to an instance of that field with SET for all other instances. However, if you then refresh the word document (select everything with CTRL + A and press F9), you will see that each instance of the field will get updated correctly and there will be a different value for each. This is the behaviour I was expecting to begin with.

Scenarios: This issue only happens with embedded tables within other fields: if the table is not in another field, Aspose updates correctly. It also works correctly if the SET field is in another field (but not in a table). Another correct case is if each field name is unique.

Steps to reproduction

I prepared an example program to allow you to reproduce and see the issue for yourself. Please have a look at the archive file “fieldUpdateError.zip” (zipped without Aspose libraries, so you would need to add them yourself). FieldUpdateError.zip (21.5 KB)

Input.docx contains two blocks: each block contains a field. This field only contains a table. This table contains “SET myfield [unique value]”. The table contains nothing else. After this, I check the value assigned to myfield. The second block behaves exactly like the first block I just described. It uses the same field name (myfield) but assigns a different value to it.

On execution of the program, both field values for myfield in the input.docx will be refreshed with “Document.updateFields()” from Aspose. A new file output.docx will be created with the unfortunate results: when opening the generated output.docx file, you can see that both cases only have the last field value assigned to them, which is not correct.

However, if you then refresh the word document (select everything with CTRL + A and press F9), you will see that the field values will get updated correctly and there will be a different value for each myfield. This behaviour from Microsoft Word updates correctly and this is what I need from the Aspose Word library.

Comments and further information can be found in the source code.

Effect on our customers

My customers present me with predefined templates and expect the result to behave exactly like in Microsoft Word. The example input file I provided is a much-simplified version of an actual customer template and mirrors its issues. As soon as a report is generated with Aspose, the aforementioned error happens and needs to be manually corrected every single time (which is not even possible at all times, since the document will in some cases be saved as .pdf). Since this is supposed to be an automatic solution, using the report like this leads to a lot of customer dissatisfaction.

Solution or workaround possible?

Is there another way to implement this functionality as intended without introducing unique field names or changing the core structure of the input file (which unfortunately is not possible due to client restrictions)? Is there another way for me to refresh the document correctly without having to do it manually after generation in Word? Or is the described behaviour an actual bug in Aspose and I can expect it to be corrected soon in future builds?

I would be grateful for a swift solution to my problem. Thank you in advance!

Best regards,
Alexander Lyalin

Eudemonia Solutions AG

@Alex-Reporter,

Thanks for reporting this problem to us. We tested the scenario and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-20330. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.

The issues you have found earlier (filed as WORDSNET-20330) have been fixed in this Aspose.Words for .NET 20.6 update and this Aspose.Words for Java 20.6 update.

Please excuse my late reply, thank you very much, I tried it out. This is exactly the solution to my problem.
Thanks a lot.

@Alex-Reporter,

Thanks for your feedback. In case you have further inquiries or may need any help in future, please let us know by posting a new thread in Aspose.Words’ forum.