IF statement

First go at this merge, and this I need to do an if statement:

IF { MERGEFIELD contactdetails } <> “1” “Contact details: { MERGEFIELD adName} - { MERGEFIELD adline1},” “Contact details: {MERGEFIELD orgHead} - {MERGEFIELD orgName},”

This doesn’t seem to work. Are IF statements supported?

Cheers

Hi,

Aspose.Word supports merge fields, but does not support (evaluate) conditional expressions and does not support nested fields (which are required in your example).

We think it is better to write logic in the code, not in a Word document. Your example can easily be resolved if you have control over the document and can change it to:
Contact details: { MERGEFIELD myName} - { MERGEFIELD myAdLine1}

Then you have a choice:
1. You can build your database query to do the “contactdetails <> 1” check and put appropriate data into myName and myAdLine1 columns.
2. You can respond to MailMerge.MergeField event in a way something like this:

private void HandleMergeField(object sender, MergeFieldEventArgs e)
{
if (e.FieldName == “myName”)
{
//Select data from different data table fields depending on a value in another database field.
string srcFieldName = (myDataTable[“contactDetails”].Value != 1) ? “adName” : “orgName”;
e.Text = myDataTable[srcFieldName].Value;
}
… similar for myAdLine1 field
}

Please check out related discusssion .

Please come back if this solution is not suitable and you have to use IF fields.