Add Conditional Logic to a Document Template in Dochly
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.
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".
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}}".
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.
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.
Show entirely different page layouts or document sections depending on record type, deal size, region, or any other field. One template handles all variants.
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).
StageName, Amount, Account.Type, Custom_Field__c. Use dot notation for related objects.equals, not equals, contains, greater than, is blank, etc. The full operator reference is in the table below."Closed Won"), a number (10000), a date, or another merge field. Leave blank when using is blank or is not blank operators.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:
| Operator | Meaning | Best used for |
|---|---|---|
| = / equals | Field value exactly matches | Picklist values, record types, exact text — e.g. StageName = "Closed Won" |
| != / not equals | Field value does not match | Excluding a specific value — e.g. Type != "Partner" |
| contains | Field value includes the string | Text fields with variable content — e.g. Description contains "urgent" |
| not contains | Field value does not include the string | Excluding records where a keyword is present |
| starts with | Field begins with the string | Account Name starts with "The" — useful for sorting/grouping |
| > / greater than | Number or date is greater | Amount > 50000, CloseDate > TODAY |
| >= / greater than or equal | Number or date is greater or equal | Discount_Pct__c >= 15 |
| < / less than | Number or date is less | Amount < 1000, Days_Until_Expiry__c < 30 |
| <= / less than or equal | Number or date is less or equal | Probability <= 25 (low-probability deals) |
| is blank | Field has no value (null or empty) | Showing a fallback section when an optional field is empty |
| is not blank | Field has any value | Showing a section only when a field has been filled in |
| is true | Checkbox field is checked | Conditional content based on a checkbox — e.g. Is_Renewal__c is true |
| is false | Checkbox field is unchecked | Showing 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.
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.
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.
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.
Build the condition
In the condition builder, click Add Condition. Three dropdowns appear: Field, Operator, Value.
- Field: Select
Amountfrom 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.
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.
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.
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.
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
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.
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.
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.
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.
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
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.
Rated 5 stars · Native Salesforce app · Free to install