Mail Merge and nested fields

I would like to achieve something like the following possibly by using conditional mail merge.
“If someFieldMeetsCondition then insert some text a Merge Field and some more text.” (Bold for emphasis only)

{IF {MERGEFIELD PurchaseDate} != "" The purchase {MERGEFIELD Description} was approved on {MERGEFIELD PurchaseDate}.
The above definition of the mail merge is not syntactically correct, but I’m at a loss of how to get this working.

Hi

Thanks for your inquiry. You should use “<>” instead of “!=”. For example, see the following field code:
{ IF "{ MERGEFIELD test }" <> "test" "this is my mergefield { MERGEFIELD myfield }" "" }
Hope this helps.
Best regards.

Thank you for your response.
Maybe I’m not entering the data in Word correctly. Could you please attach a Word (docx) file with a properly defined Merge field? Given the values you used above should the following code work? (note that the value for the test field <> “test” )

Document doc = new Document(@"c:\temp\mailmergetest.docx");
string[] keys = {
    "test",
    "myfield"
};
object[] values = {
    "test value",
    "myfield value"
};
doc.MailMerge.Execute(keys, values);
doc.Save(@"c:\temp\mailmergetest-saved.docx");

Clarification: When the value of “test” = “” there should not be any text rendered.
I have not been able to find any sample projects that demonstrates conditional mailmerge. If you have any that would be helpful as the above is only a sample - we have more complex scenarios as well.

Hi

Thanks for your inquiry. I attached my input and output documents. Also, here is code I used for testing, it is the same as you have provided:

Document doc = new Document(@"Test001\in.doc");
string[] keys = {
    "test",
    "myfield"
};
object[] values = {
    "test value",
    "myfield value"
};
doc.MailMerge.Execute(keys, values);
doc.Save(@"Test001\out.doc");

Please make sure you are using the latest version of Aspose.Words (7.0.0). IF fields evaluation feature is available starting from this version:
https://docs.aspose.com/words/net/update-fields/
You can download the latest version from here:
https://releases.aspose.com/words/net
Best regards.

Alexey, Thank you!