Help Center Conditional Logic Add Conditional Logic to a Template

Add Conditional Logic to a Document Template in Dochly

Updated June 2026 9 min read Conditional Logic
Conditional logic lets a single Dochly template produce different documents for different Salesforce records — showing or hiding sections, switching text based on field values, changing formatting, filtering table rows, and branching entire document structures. All without building separate templates for every scenario. This guide covers the fundamentals: what conditions are, how they work, every operator, and how to add your first condition to any template element.

What conditional logic does

Every condition in a Dochly template is an instruction that evaluates a Salesforce field value at document generation time and takes an action based on the result. The condition runs against the live data on the record being generated — so the same template produces different output for different records.

Show or hide content

Include or exclude entire sections, paragraphs, tables, or individual sentences based on any Salesforce field. Example: show the "Payment Terms" section only when Payment_Type__c = "Credit".

Switch text with if/else

Output different text depending on a field value. Example: "This agreement is governed by the laws of {{if Region = 'EU'}}the European Union{{else}}England and Wales{{/if}}".

Filter table rows

Show only the table rows that meet a condition from a related list. Example: show only line items where Line_Type__c = "Product" — exclude service line items from an invoice.

Apply conditional formatting

Change font colour, bold, background, or border based on a value. Example: highlight overdue payment rows in red when Days_Overdue__c is greater than 30.

Branch document structure

Show entirely different page layouts or document sections depending on record type, deal size, region, or any other field. One template handles all variants.

Conditional related list content

Include related records only when they meet criteria — e.g. show only active products in a quote, or show only open tasks in a project summary.


Anatomy of a condition

Every condition in Dochly has the same structure — a field to evaluate, an operator to compare with, a value to compare against, and an action to take when the condition is true (and optionally, a different action when false).

Condition structure
Field
The Salesforce field to evaluate. Can be any field on the primary object or related objects — StageName, Amount, Account.Type, Custom_Field__c. Use dot notation for related objects.
Operator
How to compare the field value — equals, not equals, contains, greater than, is blank, etc. The full operator reference is in the table below.
Value
What to compare the field against — a static value ("Closed Won"), a number (10000), a date, or another merge field. Leave blank when using is blank or is not blank operators.
Then (action)
What to do when the condition is true — show content, hide content, apply formatting, output specific text, or use a nested condition.
Else (optional)
What to do when the condition is false — show different content, apply different formatting, or output fallback text. Omitting the else branch means nothing is shown when the condition is false.

In the Dochly template editor, conditions can be built using either the visual condition builder (point-and-click dropdowns) or the syntax editor (for complex nested conditions). This guide focuses on the visual builder — see the dedicated guides for if/else syntax and dynamic tables.


Operators reference

Every condition uses an operator to define how the field value is compared. Here is every available operator and when to use each:

OperatorMeaningBest used for
= / equalsField value exactly matchesPicklist values, record types, exact text — e.g. StageName = "Closed Won"
!= / not equalsField value does not matchExcluding a specific value — e.g. Type != "Partner"
containsField value includes the stringText fields with variable content — e.g. Description contains "urgent"
not containsField value does not include the stringExcluding records where a keyword is present
starts withField begins with the stringAccount Name starts with "The" — useful for sorting/grouping
> / greater thanNumber or date is greaterAmount > 50000, CloseDate > TODAY
>= / greater than or equalNumber or date is greater or equalDiscount_Pct__c >= 15
< / less thanNumber or date is lessAmount < 1000, Days_Until_Expiry__c < 30
<= / less than or equalNumber or date is less or equalProbability <= 25 (low-probability deals)
is blankField has no value (null or empty)Showing a fallback section when an optional field is empty
is not blankField has any valueShowing a section only when a field has been filled in
is trueCheckbox field is checkedConditional content based on a checkbox — e.g. Is_Renewal__c is true
is falseCheckbox field is uncheckedShowing content only for new (non-renewal) agreements

Adding your first condition to a template

This walkthrough adds a condition to a paragraph — showing a "Volume Discount Terms" paragraph only when the Opportunity Amount is greater than £50,000.

1

Open the template in the editor

Go to Dochly → Templates → select your template → click Edit. Set the template to Draft if it is currently Active — editing an Active template generates a new draft version. Alternatively, click Clone to work on a copy without affecting the live template.

2

Select the element to conditionalise

Click the paragraph, table, section, or text block you want to show or hide based on a condition. The element is highlighted with a selection border. Any element in the template can have a condition applied — paragraphs, tables, table rows, images, and entire sections.

For this example, click the "Volume Discount Terms" paragraph.

3

Open Conditional Logic in the element properties

With the element selected, the right-hand properties panel shows element settings. Click the Conditional Logic tab (or Conditions icon — it looks like a branching arrow). The condition builder panel opens.

4

Build the condition

In the condition builder, click Add Condition. Three dropdowns appear: Field, Operator, Value.

  • Field: Select Amount from the field picker (search for it or browse the Opportunity fields list)
  • Operator: Select greater than
  • Value: Type 50000

The condition now reads: IF Amount > 50000.

5

Set the action (show when true)

Below the condition, set the Action dropdown. For show/hide conditions, the options are:

  • Show when condition is true — the element is included when the condition passes; hidden when it fails
  • Hide when condition is true — the element is hidden when the condition passes; shown otherwise

Select Show when condition is true. The "Volume Discount Terms" paragraph will now only appear in generated documents when Amount > 50,000.

6

Save and test

Click Save on the template. To test the condition, use the Preview function — select two test records: one with Amount > 50,000 and one with Amount ≤ 50,000. Verify the paragraph appears in the first preview and is absent in the second.

Always test both the true and false outcomes before setting the template to Active.


Multiple conditions and AND/OR logic

A single element can have multiple conditions. Use AND logic when all conditions must be true; use OR logic when any one condition being true is sufficient.

AND logic

All conditions must pass for the action to trigger. Example: show the "Enterprise SLA" section only when Account.Type = "Enterprise" AND Amount > 100000. Both must be true — a large non-enterprise deal doesn't see it, and an enterprise deal under threshold doesn't either.

OR logic

Any one condition passing triggers the action. Example: show the "Compliance Notice" section when Region = "EU" OR Region = "UK". Either region sees the notice — you don't need to list every EU country individually.

// AND example — both must be true IF Account.Type = "Enterprise" AND Amount > 100000 THEN show "Enterprise SLA" section // OR example — either is sufficient IF Region__c = "EU" OR Region__c = "UK" THEN show "GDPR Compliance Notice" section

You cannot mix AND and OR within a single condition group in the visual builder — all conditions in one group are either all-AND or all-OR. For mixed logic (e.g. "A AND (B OR C)"), use nested conditions or the syntax editor. See Use if/else conditions for nested logic.


Nested conditions

Nested conditions allow you to evaluate a second condition inside the else branch of a parent condition — producing three or more different outcomes from a single element.

// Nested condition — three outcomes from one element IF Amount > 100000 THEN show "Enterprise Pricing" paragraph ELSE IF Amount > 25000 THEN show "Growth Pricing" paragraph ELSE show "Standard Pricing" paragraph

In the visual builder, nested conditions are added by clicking Add Else-If Branch in the condition panel. Each branch evaluates only when the previous branch's condition was false — conditions are evaluated in order from top to bottom. The first branch that passes is used; the rest are skipped.


Common conditional logic use cases

Picklist field condition

Show different payment terms based on Account payment type

Condition: Payment_Type__c = "Credit". Show the credit payment terms section. Else: show the standard payment terms section. One proposal template handles both payment arrangements.

Number field condition

Include volume discount clause only for large deals

Condition: Amount > 50000. Show the volume discount clause. Else: hide it. Ensures the discount clause never appears on small-deal proposals by mistake.

Checkbox field condition

Add renewal-specific language for returning customers

Condition: Is_Renewal__c is true. Show the renewal preamble paragraph referencing the previous agreement. Else: show the new customer introduction paragraph. The same contract template serves both.

Region field condition

Show GDPR compliance section for EU customers

Condition: Account.BillingCountry is in EU country list. Show the GDPR data processing section. Else: show the standard privacy notice. Eliminates manual selection of the right template by region.

Blank field condition

Show a fallback message when an optional field is empty

Condition: Custom_Terms__c is blank. Show "Standard terms apply as per the master services agreement." Else: show the Custom_Terms__c field value. Never sends a document with a blank terms section.


Frequently asked questions

Yes — conditions can be applied to paragraphs, individual sentences, tables, table rows, table columns, images, sections, headers, and footers. The condition builder is available for any selectable element in the template editor. The most common applications are sections (show/hide large blocks), table rows (filter data rows), and inline text (if/else text switching).
Yes. Formula fields on Salesforce objects are available in the Dochly field picker just like standard fields. Dochly reads the formula field's calculated value at generation time. This is a powerful pattern — create a Salesforce formula field that categorises records into groups (e.g. "Tier_1", "Tier_2", "Tier_3" based on Amount) and then use that formula field in a simple equals condition rather than building complex numeric range conditions in Dochly.
Use the Preview function in the template editor — it lets you generate a preview from any real Salesforce record in your org. To test conditions properly, preview against at least two records: one that meets the condition and one that doesn't. Confirm the conditional elements appear and are absent as expected in each preview. Previews don't count toward your document generation usage.
Yes. Related object fields are available using dot notation in the field picker — e.g. for an Opportunity template, you can use Account.Type, Account.BillingCountry, or Contact.Title. Go up to two relationship levels from the primary object. Fields more than two hops away are not directly available — for deep relationship fields, create a formula field on the primary object that pulls the value closer, then use that formula field in the condition.

You've added your first conditional logic rule. Next in this series: Show or hide document sections based on Salesforce fields — the most common conditional logic pattern, with examples for proposals, contracts, invoices, and compliance documents.

Dochly
Salesforce AppExchange — UTECH HUB Install Dochly on AppExchange

Rated 5 stars · Native Salesforce app · Free to install