MailMerge IF fault

There appears to be a fault in the MailMerge which is producing a false positive when comparing the strings “Grade 01” and “Band 1”. From what I can tell this is not a fault with Word but with Aspose.Words.

I’m using Aspose.Words v23.2.0 in production, but I’ve also confirmed the fault in the latest v23.5.0

The following merge fields have been setup in my test document…

{ IF { MERGEFIELD GRADE } = "Grade 01" "This is Grade One" "This is NOT Grade One" }
{ IF { MERGEFIELD GRADE } = "Band 1" "This is Band One" "This is NOT Band One }

The data source is then sending in "Grade 01" for the GRADE field, however BOTH result in the true value being displayed, i.e.

This is Grade One
This is Band One

This is also the same output if the data source is Band 1which makes me think that the code is matching the integer value at the end of the string, rather than the entire string?

If you “Update Field” on both (by using CTRL-F9, right click the fields, then CTRL-F9 to put back) then it shows the correct values, i.e.

This is Grade One
This is NOT Band One

I have an example project for you - but would like this thread to be made private before I upload it.

Thanks,
Tom

@stonefish You should enclose merge fields in into double quotes since the value might contain whitespaces. Please try modifying your template like this:

{ IF "{ MERGEFIELD GRADE }" = "Grade 01" "This is Grade One" "This is NOT Grade One" }
{ IF "{ MERGEFIELD GRADE }" = "Band 1" "This is Band One" "This is NOT Band One }

Thanks @alexey.noskov

If I take the output document that is produced and click CTRL-F9 it comes out as following (with quotes already in place) which makes me think they’re unnecessary…

{ IF "Grade 01" = "Grade 01" "This is Grade One" "This is NOT Grade One" }
{ IF "Grade 01" = "Band 1" "This is Band One" "This is NOT Band One }

However, you are right… adding quotes around the merge fields does fix it in Aspose.Words.

My issue is that if I run the exact same template (without quotes) through Word itself using a data source, it works without the quotes.

It’s also worth noting that the client who reported the issue has multiple templates with over 1200 merge fields in it… I’m not telling them to update them all with quotes!

@stonefish You are right the second IF field is not properly updated by Aspose.Words upon execution mail merge when merge field is not enclosed into double quotes.

Document doc = new Document(@"C:\Temp\in.docx");
doc.MailMerge.Execute(new string[] { "GRADE" }, new string[] { "Grade 01" });
//doc.UpdateFields(); // <- fixes the problem
doc.Save(@"C:\Temp\out.docx");

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-25372

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

1 Like

Thanks @alexey.noskov - much appreciated

Ah, @alexey.noskov - I’ve only just noticed the fixes the problem line in your example.

I’ve tried it in my local console app (not in the full system yet) and it appears to work correctly as you state.

I presume this will not cause any unwanted side-effects, and that we could release a fix with that line included to our production system?

@stonefish This will not cause any unwanted side-effects, since fields are actually update upon execution mail merge. But for some reason in this particular case IF field is not update properly.

1 Like

@alexey.noskov - you’re normally good at updating these tickets if something has been resolved, so as there’s nothing here I have to assume the above has not been fixed.

We now have another issue that’s been reported to us, which could be related and appears to have been introduced as part of v23.7.0, and also exists in the latest v23.9.0.

After we have processed the mail merge document (including the extra call to .UpdateFields()) we enumerate through the results of doc.MailMerge.GetFieldNames() and compare those fields to the list of columns in the data source… anything that doesn’t match is highlighted to the user (so they’re aware they’ve used a field that doesn’t exist in the data).

As of v23.7.0 there appears to be an issue where IF statements are being processed, but the true value of the statement is being returned to us as a merge field.

So in the following example, GetFieldNames() is returning AppId is 80 instead of APP_ID

{ IF "{ MERGEFIELD APP_ID }" = "80" "AppId is 80" "AppId is not 80" }

It’s also worth noting that in my test data APP_ID is not 80… so the document in question merges correctly to show AppId is not 80 but the GetFieldNames still returns AppId is 80

@stonefish The issues WORDSNET-25372 is already resolved in the current codebase. The fix will be included into the next 23.10 version of Aspose.Words.

regarding the another issue. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-25983

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

The issues you have found earlier (filed as WORDSNET-25372) have been fixed in this Aspose.Words for .NET 23.10 update also available on NuGet.

The issues you have found earlier (filed as WORDSNET-25983) have been fixed in this Aspose.Words for .NET 23.11 update also available on NuGet.