Let the platform do the work

Filtering with Conditionals in Doc Merge

Overview

In addition to the ability to use Sugar Logic formulas in documents templates, you can use condition-based logic by manually constructing IF/ELSE IF statements. If you are familiar with the wDocs tool, these statements are constructed through "Conditionals" in the Template Builder. This article describes how to manually construct these statements in a Doc Merge document template and provides example templates you can modify and use to meet your needs.

Constructing Statements

Condition-based logic returns a field in document templates when the identified condition is true. Construct statements using the syntax shown in the following example:

{#module} {if fieldname1=="value1"} {fieldname2} {elseif fieldname1=="value2"} {fieldname3} {else} {endif} {/module}

Rules

The following rules apply to conditional statements:

  • When using multiple conditional statements, each statement must be on a separate line in the document template.
  • String variables must be embedded in quotation marks, as shown in the above example.

Operators

The following operators are allowed in conditional statements:

Operator Description
= attribution
== equal
!= not equal
< less than
<= less than or equal to
> greater than
>= greater than or equal

 

Examples

The following examples demonstrate conditional statements. Please also refer to the Sample Document Templates page for document template examples you can download.

Opportunities based on description

The following statement will populate the merged document with the opportunity name and amount if the Sales Stage field is "prospecting" or if the Sales Stage field is "negotiation/review":

{#opportunities} {if sales_stage=="prospecting"} {name} {amount} {elseif sales_stage=="negotiation/review"} {name} {amount} {else} {endif} {/opportunities}

Opportunities in progress

The following statement will populate the merged document with the opportunity name, amount, and date closed when the status is "In Progress":

{#opportunities} {if status=='In_Progress'} {name} {amount} {date_closed} {endif} {/opportunities}

Accounts in a specific industry

The following statement will populate the merged document with text strings based on the industry type:

{#accounts} {if industry=='Apparel'} "This account is in the Apparel industry" {elseif industry=='Banking'} "This account is in the Banking industry" {else} "The industry for this account is unknown " {endif} {/accounts}

Suppressing blank rows in a table

Using the following segment will eliminate blank rows if the field has no value, which is especially useful when working with tables:

{if billing_address_street_2}{billing_address_street_2}{endif}