We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

MailMerge - nested fields lazily evaluated?

Hello Team,

I've noticed a strange behaviour while running Mail Merge on document using Aspose. Considering the case as per attached documents (source document is provided without input merge data, which is pretty easy to prepare, I believe), it looks like Aspose.Words performs MailMerge only on these fields which are required during evaluation of logical expressions (e.g. IF fields). Merge fields which are not used during evaluation are omitted - even when a value for them exists in mail merge data source, Based on examples attached, it looks like in case when IF condition is resolved as true, value for False is not evaluated - and the same in the opposite case. The code which I used is:

var document = new Document(path);
document.FieldOptions.FieldUpdateCultureSource = FieldUpdateCultureSource.FieldCode;
document.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveUnusedFields;
document.MailMerge.Execute( mergeData );

Could you please provide some explanation on this? Is it an expected behaviour? If not, could you please suggest any workaround on this? We don't want to end up with a result document which contains not evaluated merge fields, especially when input data for these fields exists in our data source. On the other hand, our requirement is to keep IF fields in the document after processing, so setting MailMergeCleanupOptions.RemoveContainingFields is not an option for us.

Best Regards,
Rafał
Hi Rafał,

Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does.

You are facing the expected behavior of Aspose.Words. It does not populate merge fields inside false part of IF field. The cleanup options are not applied too. So, false part of IF field remains unchanged, like in MS Word mail merge preview.

Please read the detail of this API change from here:
Public API Changes in Aspose.Words 15.12.0

Hi Tahir,


Many thanks for specific information about this.

Thanks,
Rafał