If Statements / If Fields / Comparison Statements

IF statements (also called IF fields) allow you to compare two values and display document content based on the result of the comparison. When used in a Word template, IF statements are especially useful for comparing the values of Composer merge fields and then displaying the appropriate content.

Example use cases:

  • If an Account’s billing country is not in the United States, display information about international shipping terms. Otherwise, show domestic shipping terms.
  • If a Contact’s mailing address is blank, show the billing address from his related Account. If it’s not blank, show the Contact’s mailing address.
  • If an Opportunity’s amount is greater than $10,000, show information about a complimentary service package. If not, show nothing.

Nested IF statements in Word, where the else value is another IF statement, will work with Conga Composer but are not recommended. Conga Technical Support will not assist with nested IF statements. Conga highly recommends evaluating nested IF statement logic using Salesforce formula fields and then merging the formula field values into the document.

Watch this video on How to Add IF Statements to Templates.

Create IF Statements in a Word Template

IF statements can use Word merge fields or text-based merge fields, with one exception: the IF statement itself must be a Word merge field. This means that all the fields inside or around the IF statement can be either Word or text-based merge fields, but again, the IF statement itself must be a Word merge field.  Following are examples of both types of syntax.

Syntax

{IF "Expression 1" Operator "Expression 2" "TrueValue" "FalseValue"}

Below is a very basic example using Word merge fields as Expressions. The single braces ({ }) on either end of the IF statement indicate the beginning and end of a Word merge field when the field codes have been toggled open.

{IF "{{Opportunity_Amount}}" > "100000" "Big Deal Opptye" "Normal Oppty"}

Components of an IF Field

Expression1 & Expression2:

  • Both Expression1 and Expression2 represent fields and values that you want to compare.
  • Expressions are usually Word or text-based merge fields, text strings, or numbers. Expression1 and Expression2 should be surrounded with quotation marks ("").

Operator

  • A comparison operator. There is always a space before and after the operator.
  • Supported operators:

TrueValue & FalseValue

  • Content that is shown when the comparison is true (TrueValue) or false (FalseValue). Each must be surrounded with quotation marks.

If the content of your TrueValue or FalseValue contains quotation marks ( “ or ” ), you need to replace those quotes with two pairs of single quotation marks (‘’ ‘’ instead of “ ”). Otherwise, Word will consider the first quotation mark from your merged data as the end of your text string and the IF statement will not work.

Creating an IF Field - Conga Best Practices

It is important to follow best practices to ensure the stability and sustainability of your IF statements. In the example below, we will show in detail the best practice method for creating IF statements.  We will also show the syntax for both Word merge field and text-based merge fields.

Example scenario: If the Opportunity Amount is greater than $10,000, show information about a complimentary service package. If it's not, do not show anything.

We recommend the following approach:

Procedure StepResult
Create a traditional merge field with a placeholder name.«IF_Amount>10000»
Open the merge field by toggling field codes.{MERGEFIELD IF_Amount>10000 \* MERGEFORMAT}
Delete the contents of the field, entering IF instead.{IF}
Add Expression1 to the IF field. In our example, Expression1 is the Opportunity Amount field.

Word

{IF “«OPPORTUNITY_AMOUNT»”}

Text-based

{IF “{{OPPORTUNITY_AMOUNT}}”}
Insert your Operator. We're using greater than (>).

Word

{IF “«OPPORTUNITY_AMOUNT»” >}

Text-based

{IF “{{OPPORTUNITY_AMOUNT}}” >}
Insert Expression2. Our example is $10,000.

Word

{IF “«OPPORTUNITY_AMOUNT»” > “10000”}

Text-based

{IF “{{OPPORTUNITY_AMOUNT}}” >  “10000”}
Insert TrueValue. Our example is a merge field that displays the details of a complimentary service package.

Word

{IF “«OPPORTUNITY_AMOUNT»” > “10000” “«OPPORTUNITY_SERVICE_PACKAGE»”}

Text-based

{IF “{{OPPORTUNITY_AMOUNT}}” > “10000” “{{OPPORTUNITY_SERVICE_PACKAGE}}” }
Insert FalseValue. In our example, we don't want to display anything if the Opportunity Amount is less than $10,000, so our FalseValue is null.  This is represented by a pair of quotation marks.

Word

{IF “«OPPORTUNITY_AMOUNT»” > “10000” “«OPPORTUNITY_SERVICE_PACKAGE»” “”}

Text-based

{IF “{{OPPORTUNITY_AMOUNT}}” > “10000” “{{OPPORTUNITY_SERVICE_PACKAGE}}”  “”}

Our finished IF field looks like this:

Word
{IF “«OPPORTUNITY_AMOUNT»” > “10000” “«OPPORTUNITY_SERVICE_PACKAGE»” “”}

Text-based
{IF “{{OPPORTUNITY_AMOUNT}}” > “10000” “{{OPPORTUNITY_SERVICE_PACKAGE}}”  “”}

An IF statement that is toggled open should look exactly like the examples above when it is completed.  When initially creating the IF statement, Word will include the following text at the end: \* MERGEFORMAT. This text needs to be removed to ensure the IF statement renders consistently.

When we toggle the field codes closed, the IF statement will revert to the Word merge field with the placeholder name:

«IF_Amount > 10000»

Using the IF statement we just created, let’s consider an example:

The Merge Nation Opportunity has an amount of $25,000. Once we merge the Composer template that uses our IF statement, our merged document will look like this:

We are showing the value of the OPPORTUNITY_SERVICE_PACKAGE field since that is our TrueValue.

Now let's say we use a different Opportunity called Merge Republic, which only has an amount of $8,000. Our merged document will show nothing (""), since that is our FalseValue.

Warnings

  • Checkbox fields: Although the Composer View Data Workbook and the Template Builder show the values of checkbox fields as TRUE and FALSE, those values do not work in an IF statement. Change your value from TRUE to True.
    Example: {IF "<<Checkbox_MergeField>>" = "True" "Yes" "No"}
  • Tables: IF statements placed inside a table row cannot hide the table row when the statement evaluates to show nothing.  You will instead have a blank table row. Word IF statements cannot be used to hide rows within a table.
  • IF statements do not work in a Conga Email template.