IF Statements Not Resolving in 18.7

We are evaluating moving from Aspose.words version 15.11 to version 18.7 and have found that in one of our customers with complex IF conditions, combined with ASK fields, some of their templates are no longer resolving these IF conditions.

I have put together a sample project that shows the issue. If you reference the 15.11 dll, the statements resolve. If you reference the 18.7 dll, they do not.

How do I go about providing the sample project to you? The support has changed, is this option still available to me?

@jheltibrand,

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

  • Your input Word document
  • Aspose.Words 15.11 generated output DOCX file showing the undesired behavior.
  • Aspose.Words 18.7 generated output DOCX file showing the wrong output.
  • Please 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 remove DLL files from this project 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.

P.S. If your ZIP file size is big, you can upload the ZIP file to Dropbox and share the download link here for testing.

The input document is included in the project folder, it is named “Waiver With Plea Agreement POM 08_06_16 to Present.docx”.

The column Def_Sex in the dataset is being set to a value of M (shown below), so the if statements should all resolve to “he” and “his”.

image.png (30.7 KB)

Set your aspose.words reference to version 15.11, and run the project. The merged document will come up. Press ctrl-a to select all text and press F9 to trigger the ASKs. Choose the first choice in each. Scroll down to section 5. You will see that the IF statements resolve correctly to “he”.

image.png (41.3 KB)

Now change your reference to version 18.7 and repeat the process. Here you will see that the IFs are not being evaluated correctly.

image.png (44.2 KB)

TestAsposeWordsIFIssue.zip (291.0 KB)

@jheltibrand,

We have used your application to generate a couple of output documents on our end. (see outputs.zip (114.7 KB))

MergedDoc-18.7.docx was produced by using Aspose.Words for .NET 18.7 and
MergedDoc-15.11.docx was produced by using Aspose.Words for .NET 15.11.

Please create a comparison screenshot highlighting (encircle) all the problematic areas in this MergedDoc-18.7.docx output document (with respect to MergedDoc-15.11.docx) and attach it here for our reference.

You did not follow the directions. There are ASK fields that need responses. When your merged document comes up, you need to select all on the doc, then press F9, and answer the three ASKs. Answer A, D, and 1 (this will make sense when you are prompted).

The 15.11 doc resolves the Def_Sex mergefield correctly, since it is being set to a value of M (for Male:

image.png (30.5 KB)

The 18.7 doc does not, it is not resolving the mergefield Def_Sex, resulting in values of “she” instead of “he”:

image.png (33.8 KB)

These two screenshots were taken from the two documents you provided in your zip file.

@jheltibrand,

Thanks for the additional information. For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-17259. 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.

@jheltibrand,

Regarding WORDSNET-17259, we have completed the analysis of your issue and come to a conclusion that this issue is actually not a bug in Aspose.Words. So, we have closed this issue as ‘Not a Bug’.

The sample document contains following IF and ASK fields (simplified)

{ ASK AskBook ... }
{
	IF { REF AskBook } = "A"
	"{ IF { MERGEFIELD Def_Sex } = "M" "he" "she" }"
	"
		IF { REF AskBook } = "B"
		"{ IF { MERGEFIELD Def_Sex } = "M" "he" "she" }"
		"
			IF { REF AskBook } = "C"
			"{ IF { MERGEFIELD Def_Sex } = "M" "he" "she" }"
			""
		"
	"
}

The nested merge fields are not merged, because the root level condition is false during mail merge. MS Word behaves the same. We implemented this behavior in 15.12 version.

As we understand you use following scenario:

  • perform mail merge with Aspose.Words
  • modify document in MS Word by ASK fields

So, the only workaround we have found is perform extra mail merges with IFieldUserPromptRespondent:

doc.MailMerge.ExecuteWithRegions(dataSet);
foreach (string value in new string[] { "A", "B", "F", "H", null })
{
    doc.FieldOptions.UserPromptRespondent = new FieldUserPromptRespondent(value);
    doc.MailMerge.Execute(new string[] { "Def_Sex" }, new object[] { "M" });
}

class FieldUserPromptRespondent : IFieldUserPromptRespondent
{
    private readonly string mValue;

    public FieldUserPromptRespondent(string value)
    {
        mValue = value;
    }

    public string Respond(string promptText, string defaultResponse)
    {
        return promptText == "Enter the strike type: A, B, F, or H"
            ? mValue
            : defaultResponse;
    }
}

However, it only works when root level dataset has only one record.

If I understand correctly, at the time of doc.MailMerge.ExecuteWithRegions the REF to AskBook is not set, so therefore no evaluation of the merge field will take place?

This is behavior that my customers have created thousands of templates based on, and now you no longer support it? Why has this changed from version 15.11? This used to work perfectly well for us.

Is it the policy of Aspose to routinely remove functionality like this?

@jheltibrand,

This is not a regression issue in Aspose.Words. We implemented this functionality to make Aspose.Words’ Mail Merge engine closer/same to the MS Word’s Mail Merge. In this case, you will get the same output when you do Mail Merge by using MS Word.

No, it is not common practice for us to make functionality breaking changes to the API and we try to avoid this whenever possible, but sometimes it is necessary. This new behavior was implemented in 15.12 and latest versions of Aspose.Words to mimic MS Word’s mail merge functionality.

Do I have any other recourse on this issue? Is there anyone I can speak to? I can imagine this will affect more than just me and my application (and my 10k+ users).

It seems to me Aspose has gone out of its way to make merging work like Word, but the result is the loss of significant functionality.

@jheltibrand,

We have noted your concerns. We have logged another issue in our issue tracking system to provide an option in Aspose.Words API to choose between the Old and the New Mail Merge behaviors. The ID of this issue is WORDSNET-17313. We will further look into the details of this requirement and will keep you updated on the status of this new issue. We apologize for your inconvenience.

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