Free Support Forum - aspose.com

MailMerge broken

Hi,

The mailmerge function is broken as it doesn’t mail merge the mergefields that are contained in the false results of IF fields.

Here is the code to reproduce this problem. You can find the test document attached.

var doc = new Document(@“mf.docx”);
var mm = doc.MailMerge;
mm.Execute(new[] { “a”, “c”, “d” }, new object[] { “a b”, “c d”, “e f” });
doc.Save(@“out1.docx”);
mm.Execute(new[] { “b” }, new object[] { “a b” });
doc.Save(@“out2.docx”);

As you can see, the “d” mergefield is never mail merged.

Any work around for this problem?

Thank you.

Hi David,

Thank you for your request. I took a look at your issue and I can see that mail merge works as expected. Fields that are contained in the false argument of the IF field are not updated, which was implemented some time ago. So it is not a broken functionality, it's rather an improvement requested by customers. Yes, it is a behavioral change, but the false argument never goes to the IF's result and therefore I cannot imagine a scenario where it could make sense. Note that Word removes the containing IF completely (which BTW is possible in Aspose.Words but is not enabled by default).

Given that, here is what is happening:
  1. During the first merge the condition is obviously true and therefore the field "d" in the false argument is not merged.
  2. During the second merge the condition becomes false, but nothing was supplied for the field "d" and it remains unmerged.
So if you want to merge the field "d" at the second step, please change the corresponding line as follows:
mm.Execute(new[] { "b", "d" }, new object[] { "a b", "x y" });

However, your sample code has revealed a bug which requires fixing indeed. The IF field fails to properly copy the argument after the "b" field is merged. We have already identified the cause of the problem and we will fix it shortly. I would like to ask my colleagues from the support team to register it as "IF field fails to update when true or false argument is merged" for the reference purpose.

So the bottom line is, we have discovered a bug thanks to your code, but it doesn't have to do with the merging of the false argument. That being said, could you please give an example of scenario that requires merging fields in the false argument of the IF field? Maybe we could provide some workaround for you then.

Thanks.

UPD. To avoid ambiguity: by "false" in the text above I meant the argument in the IF field that does not satisfy the condition, not the static false argument that always follows the true argument. :)

Hi Dmitri,


Thank you for your answer.

In our cases, we build document by combining multiple documents or parts of documents and we perform multiple mail merges. So the final evaluation of the IF fields cannot be determined by a single mail merge. That’s why we need all mergefields to be merged before they are evaluated. And we cannot predict the number of mail merges required since it depends on the data provided.
So that’s why we simply cannot use your mail merge functionnality in our scenarios since we require multiple passes.

Hope I’m clear enough.

Thanks.

P.S. My name is Pascal and I’m replacing David.

Hi Pascal,


Thanks for the additional information.
Dmitry:
IF field fails to update when true or false argument is merged.
While using the latest version of Aspose.Words i.e. 11.8.0, I managed to reproduce this issue on my side. I have logged this issue in our bug tracking system. The issue ID is WORDSNET-7048. Your request has been linked to this issue and you will be notified as soon as it is resolved.

Sorry for the inconvenience.

Best Regards,

Hi Pascal or David,


While Awais has registered the issue we discovered, we are working on your initial issue. Hopefully we can end up with some workaround for you. Could you please confirm whether you are able to redesign your documents?

@Awais, thanks for logging the issue.

Hi Dmitri and Awais,

We cannot redesign our documents since we don’t create them. And we cannot ask our customers to redesign them.

By the way, are the if fields always evaluated once one of its “operand” is mail merged? I think I noticed something like that when I tried inserting a pageref field using the documentbuilder.

Best regards,

Pascal,


Thanks for your answer. Okay, then are you able to perform mail merge only once after the final template is ready (for example, by joining your data sources that you used in consecutive mail merges)?


I will explain why I’m asking. Actually, it seems like you used to rely on an undocumented feature offered by Aspose.Words. In the past you could merge any child merge fields, wherever they were located. Now we have changed the behavior and became close to MS Word which likely skips all child fields contained in the false argument (also, please note you wouldn’t be able to merge child fields and preserve the IF field for further processing using Word at all).

Answering your question, mail merge causes the update of all fields within the merge region. Any child fields are updated (evaluated) before the containing field is updated. So the mechanism is as follows: the outer IF field’s update method is launched; it searches for child fields and updates them (and merging is simply the way merge fields are updated); finally the outer IF field is updated. The false argument’s fields are excluded from the update. Let me know if I misunderstood your question.

The issues you have found earlier (filed as WORDSNET-7048) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.