I used the following code with the attached document. The fields are replaced, but the if statements are not honored.
Document doc = new Document(“C:\Users\XXXX\Documents\MailMergeTest\TestTemplate.docx”);
String[] fieldNames = new String[] {“First_Name_D”, “Last_Name_D”, “Middle_d”, “Last_Name_Ext_D”};
Object[] fieldValues = new Object[] {“Frank”, “Tank”, “The”, “5th” };
// Execute the mail merge.
doc.getMailMerge().execute(fieldNames, fieldValues);
doc.updateFields();
doc.updatePageLayout();
doc.save(“C:\Users\XXXX\Documents\MailMergeTest\DocumentMerged.docx”);