Not getting IF conditional merge fields with doc.getMailMerge().getFieldNames()

Hi,
I’m not able to read the IF conditional merge fields.
I want to read and hold and display like other merge fields.
in the template I provided {GENDER} in IF condition. this i want to read.

The code is below specified, and please find the template file attached.
for this program the output is like below specified.

public class ReadMergeFields1 {

    public static void main(String[] args) throws Exception {

        String dataDir = "H:\\mytickets\\AsposePoc\\src\\main\\resources\\SmartMarkers\\";
        Document doc = new Document(dataDir + "in_Nested.docx");
        //String f = doc.getMailMerge().getRegionsHierarchy().getName();
        doc.getMailMerge().setUseNonMergeFields(true);

        String f1[] = doc.getMailMerge().getFieldNames();

        for (String f : f1) {
            System.out.println(f);
        }

        System.out.println("done");
    }
}

OUTPUT:

TableStart:investorTable
investorDocumentList
TableEnd:investorTable
TableStart:ipartyTable
partyName
TableStart:ipartyChildTable
documentList
TableEnd:ipartyChildTable
TableEnd:ipartyTable
NAME
SALARY

in_Nested.docx (18.8 KB)

@Rakesh_M You are using mustache syntax and field in this case should be wrapped in double curly brackets, like this {{GENDER}}.
Also, in your document IF condition should be defined using regular MS Word field. Press Alt+F9 to see field codes. Mustache syntax can be applied only to merge field themselves but not to the condition fields.
You can insert IF field either from the MS Word dialog:

or by pressing Ctrl+F9 in MS Word and typing field code.

1 Like