Overview

If you want to merge one or more sections onto your generated document based on a condition of a checkbox or formula field, you can do this using the section merge feature in the template builder. It is also possible to have one checkbox field that refers to multiple conditional merge sections in template. The section merge feature also makes it possible to create a conditional page break in your template.

  1. Conditional Merge Based on a Checkbox Field
  2. Conditional Page Break
  3. Conditional Merge Based on a Formula Field
  4. Multiple Conditional Section Merge

Conditional Merge Based on a Checkbox Field

The conditional merge feature allows you to merge sections of text into your document based on the value of a standard checkbox field (true or false). As an example, a sales rep could use the conditional merge feature to easily control whether to include or not include a “Special Terms” section in a contract document attached to an Opportunity record. To do this, they would create a checkbox field on the Opportunity object called “Special Terms”. If on the Opportunity record this checkbox field were checked (true), then this additional agreement section would merge onto the template. If this checkbox field were not checked (false), then this agreement section would not merge onto the document.

There will be a start and end to each conditional merge section that you will need to mark with tags. The template builder will generate the tags for you as part of your merge field code that you copy and paste into the document. Your conditional merge section start and end tags should be on their own line in the template. After the merging of start/end conditional section is completed within generated document, these tags and lines will be removed from the document so you will not have that extra space in document. Note that if you have a conditional merge section end tag at the end of the document template, you must add one extra line below that tag so the conditional end section end tag is not the last line of the entire document.

See the following steps to setup your conditional merge sections:

  1. Select the related checkbox field from in embedded template builder. For this example, we are using “Special Terms”.                                                                                                                                                                                                          
  2. Once you type your section name, then click on “Start of Section” to the right next to your section name and it will modify the merge field code to: {!Opportunity.Special_Terms__c[SECTION_START:Special Terms]}
  3. Copy this merge field code and paste it where you want the section to start on your template.
  4. Now go back to Section and select from drop down “End of Section” and copy the updated merge field code: {!Opportunity.Special_Terms__c[SECTION_END:Special Terms]}. 
  5. Copy this merge field code and paste it where you want the section to end on your template. 
  6. Then type in any information you would to show on document (for our example this would be the verbiage from the “Services Agreement”) or you could place a merge field inside of section that you would want to display if value is true.

Example conditional “Special Terms” section with START and END tags:

Note: If you are placing the Section End merge field at bottom of your template, this may cause “Read Time Out ” error with Google script and you can add an empty new line below the merge field to resolve so the merge field is not the last line in the template.

Conditional Page Break

You can create a page break using the conditional section merge feature as follows:

[begin conditional section]
<<add page break here>>
[end conditional section]
Note in the placement of the page break after the start of the conditional section:
   
This conditional page break ensures that, if the conditional section merge occurs, there will be a page break prior to the text within that conditional section:

Note: Conditional sections are currently not supported in related lists (tables).

Conditional Merge Based on a Formula Field

If you would like to merge conditionally without using a checkbox field, then you can create a formula field that is checkbox type and build that formula logic based on any field available to result in a true or false value. To use any logic you want, including a picklist, you can create a formula field that results in a checkbox as in true/false and put your if statements in the formula looking at the picklist field. such as If(ispickval, field, “value”,true, false).

For example, you could create a conditional merge section based on a formula field on an Opportunity record to merge ONLY if there is at least one product related to the Opportunity.

  1. Create the section and content on template builder.
  2. Create a formula field with the type as checkbox on the object merging from such as Opportunity.  The formula field in our use case could be called “Line Items Exist”.  This formula would have an IF statement to check whether the record has at least one product related to the opportunity, then return true or false.
  3. Go to the template builder and now select the new formula field just created.
  4. Check the box to make that a conditional section.
  5. Copy that merge field code to place the starting of the section at the beginning of the section, and the end at the end of the section.

Multiple Conditional Section Merge

If you would like to have one checkbox field that refers to multiple conditional merge sections in template, you can see this use case article for more detail.