MailMerge fails to update fields in document added with IncludeText

We have an application that
1, Loads a Word Docx “document” with:
.
… var _document = new Document(documentPath, options)
.
2. Reads all the Mergefields to determine what data to generate
3. Builds a DataTable for use with Mailmerge
4. Performs Mailmerge with
.
…_document.Mailmerge.Execute
.
5. And everything is fine
6. Except when “document” contains an IncludeText field that points to another Word docx document that holds Mergefields - these Mergefields are read in step 2. and are used in step 3 to build the datatable, but are not updated in the actual mailmerge.

We are using Aspose.Words for .Net version 18.5 (has also testet on version 18.10 - the problem is still there)

Please help

@StenBille,

Thanks for your inquiry. To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:

  • Your simplified input Word document(s)
  • Aspose.Words 18.10 generated output DOCX file showing the undesired behavior
  • Your expected DOCX Word document. We will investigate the structure of your expected document as to how you want your final output be generated like. You can create expected document by using MS Word.
  • Please also create a standalone simple console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing. Please do not include Aspose.Words.dll files in it to reduce the file size.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

Hereby attached a zip file with a small c# console solution that can reproduce the problem. Unzip and read the document: .\AsposeWordsTest\GuideToAsposeWordsTest.docxAsposeWordsTest.zip (59.1 KB)

@StenBille,

We have logged your problem in our issue tracking system. Your ticket number is WORDSNET-17949. We will further look into the details of this problem and will keep you updated on the status of the linked issue.

@StenBille,

Regarding WORDSNET-17949, we have completed the work on your issue and concluded to close this issue as ‘Not a Bug’. Please see the following analysis details:

The sample document contains INCLUDETEXT field with MERGEFIELD field in referenced document. The sample solution has following code:

_document.MailMerge.Execute(dataTable);
_document.UpdateFields();

The MailMerge performs as expected i.e. the MERGEFIELD field inside the INCLUDETEXT field is merged.

But, when the Document.UpdateFields method is called the INCLUDETEXT field result (with merged MERGEFIELD field) is replaced with referenced document content (with un-merged MERGEFIELD field).

So, what you need to do is to remove the last call to UpdateFields() to avoid replacing the merged document with un-merged document again. The INCLUDETEXT field is being updated during mail merge so it is enough. Hope, this helps.

I do not see that as correct behavior.

Aspose.Words has a default mailmerge destination as “A new document” and that is what we use in our mailmerge.

As I see it - Aspose.Words does not actually create a new document object, but the existing document object becomes then “new” document. (In contrast to Words own Automated Mailmerge where a new document is created)

So We expect that our document object(_document) to be “the merged document” after _document.MailMerge.Execute and therefore we expect .Updatefields to work on a document where Includetext has already been “resolved” - and therfore should not reload the unmerged mergefields.

@StenBille,

We do not fully understand what do you actually expect, but here is how Aspose.Words’ mail merge/field update works.

  1. A Document object is loaded from a file.
  2. Mail merge is executed for this document - the fields are being updated including the INCLUDETEXT field which is populated with external document’s data containing merge fields; then these merge fields are populated.
  3. Calling UpdateFields afterwards again populates the INCLUDETEXT with a document containing merge fields from the external source.

All these operations are performed on the same document instance.

Also, we are not sure what do you mean by “resolved” and why it should prevent INCLUDETEXT from being updated. Probably, you expect it to be removed from the document completely (replaced with its result) when mail merge is completed, but this is not the case. If you really need to call UpdateFields after mail merge, then you may lock the INCLUDETEXT field to prevent it from being updated. Hope, this helps.