MailMerge.getFieldNames()

Hi aspose,

I found the doc for MailMerge is not found. Could you pls explain the getFieldNames() method? Why it return different list during the merge process. Thank you!

one more question. When I use the the IF merge field with other merge fields, and the IF is nested, then multiple merge fields will be return by the getFieldNames() method:

e.g.

{IF "TRUE" "123" "{IF "TRUE" "456" "{Account.Name}"}"}

if I call the getFieldNames() before I do any merge in java thread, it return 3 Account.Name.

But if I call getFieldNames() after all merge is done, it return 2 Account.Name.

Can you explain why?

Hi Kin,

Thanks for your inquiry. MailMerge.GetFieldNames method returns a collection of mail merge field names available in the document.

Once you perform mail merge, the mail merge fields are replaced with merged values. Could you please share your input document and code example here for testing? We will investigate the issue on our side and provide you more information.

I finally found the issue.
For a nested if condition:

{IF testA "<>" "{IF testB "InnerTrue" <<InnerFalseMF>>}"}

if testA==false

The MailMerge.GetFieldNames will return empty after all merge is done.

if testA==true

The MailMerge.GetFieldNames will return a array with one item, the “<<InnerFalseMF>>” after all merge is done.*

I have no time to create a demo application for this. Can you pls confirm the above behavior? If it’s true, I think it’s a bug of aspose.

Hi Kin,

Thanks for sharing the detail. In case you are using an older version of Aspose.Words, we would suggest you please upgrade to the latest version of Aspose.Words for Java 16.1.0.

Please check following IF fields and mail merge fields. In this case, MailMerge.getFieldNames returns OuterTrueMF. Both conditions are true.

{ IF 1 = 1 "{ IF a = a <OuterTrueMF> FalseValue }" "<InnerFalseMF>" }

In following case, first condition is false and second condition is true. MailMerge.getFieldNames returns InnerFalseMF.

{ IF 1 = 2 "{ IF a = a <OuterTrueMF> FalseValue }" "<InnerFalseMF>" }

In following case, first condition is true and second condition is false. MailMerge.getFieldNames returns InnerFalseMF and OuterTrueMF.

{ IF 1 = 1 “{ IF a = b FalseValue }” “” }

You can check this behavior using following code example and attached input document. Hope this answers your query. Please let us know if you have any more queries.

Document doc = new Document(MyDir + "in.docx");
doc.updateFields();
doc.getMailMerge().execute(
new String[] { "OuterTrueMF", "InnerFalseMF" },
new Object[] { "OuterTrueMF value", "InnerFalseMF value" });
for(String item : doc.getMailMerge().getFieldNames())
{
    System.out.println(item);
}
doc.save(MyDir + "Out.docx");

Hi tahir**,**

Thank you for the confirmation.

I’ve try using aspose 15.2. All three condition return empty. I will try it later. Thank you