Overview: S-Docs Conditional Logic

Feature Overview

S-Docs Conditional Logic is a powerful feature that permits sections (or blocks) of text and data to display in your generated document only when a condition is met. This provides a mechanism to create a single template that can dynamically show and hide portions of the document based on conditional logic.

While you can also achieve simple dynamic rendering within your S-Docs templates by only using Salesforce formula fields (without the S-Docs Render feature), this approach has limitations and can be difficult to scale.

To address these limitations, S-Docs provides two levels of Rendering: Basic Render and Advanced Render.

The Basic Render feature can be used to show or hide a block of your S-Docs template based on a single condition. We suggest this approach first because it is simple and can meet most requirements.

For more complex requirements where advanced logic is needed, the S-Docs Advanced Render feature can be leveraged. The Advanced Render feature uses Salesforce apex syntax to evaluate complex and compound logical statements.

Conditional Logic With Salesforce Formula Fields

You can achieve simple rendering using only Salesforce formula fields. This technique works by using a formula field which returns either text or a blank value based on the conditional logic you set in the formula. That formula field is then simply merged into your S-Docs template just like any other merged field. While this is simple, you may reach the upper size limits of the formula field if you want to show large blocks of text.

For example, dynamically inserting "Terms and Conditions" in your document based on another field value should not be done with a formula field. Moreover, having text and logic split between your template and formula is not a good practice, as this becomes difficult to maintain.

Lastly, if you have many conditions in multiple S-Docs templates, this approach is not practical because it will require too many formula fields to be created. We therefore suggest this approach for only the simplest cases, or where the formula field already exists for other purposes. For example, if you already have a field called "Delivery Charge" and you want it to display "No Charge" for "Gold" tier customers, you may use a formula field like the one below:

IF( Tier__c="Gold", "No Charge", Fee__c)

Conditional Logic With The S-Docs Render Feature: Basic Usage

The S-Docs Render feature provides a mechanism to dynamically show or hide information without having to create additional templates for every use case. You add a render statement into your S-Docs template, and if it evaluates to TRUE, then the entire block (up to the closing ENDRENDER tag) is included; otherwise it is omitted. To use the S-Docs Render feature, you can insert the syntax yourself, or click the Insert Conditional Logic button. This document will focus on editing render syntax yourself.

We'll begin with an example. You may want to display an additional paragraph in your document if the client lives in California. Here is a snippet that you would add to your S-Docs template where you want the text to appear:

<!--RENDER='{{!Account.BillingState}}'== 'CA' -->
  This is additional information that only pertains to our clients who have a billing address in California
  <!--ENDRENDER-->

The basic S-Docs render feature supports eight basic comparators (==, !=,  >, <, >=, <=, CONTAINS and NOT CONTAINS).

Note: If any fields in your render statement contain words and have a field type anything other than a basic string type (rich text, textarea, longtext, function, etc.) you will need to add the  merge field attribute render. For example, if your merge field looked like this: {{!MyTestField}}
The field with the attribute added would look like this: {{!MyTestField render}} Within a render statement, it would look like this:
<!--RENDER= '{{!MyTestField render}}' == 'Test' -->{{!Opportunity.closedate M/d/yyyy}}<!--ENDRENDER-->
Note that this attribute should only be added to merge fields within render tags (e.g. enclosed by <!-- and -->). In the above example, the attribute  is not added to the {{!Opportunity.closedate M/d/yyyy}} because this merge field is outside of the render tags.
Additionally, note that the Insert RENDER button will not add this attribute automatically. This functionality was added in version 4.48

Render is also useful to determine if a value is empty or NULL. In the example below, we can create two render blocks. Since the value can only be null or NOT null, we are assured that only one of the render blocks below will be included in the final document output:

<!--RENDER='{{!Contact.Phone}}'== 'NULL' -->
  No Phone Number on recode. Please update.
  <!--ENDRENDER-->
  <!--RENDER='{{!Contact.Phone}}'!= 'NULL' -->
  We have the following phone number: {{!contact.phone}}
  <!--ENDRENDER-->

Finally, render can be used to assess if something is true or false (Boolean fields). Much like the example above, we can create two render blocks- one for true and one for false- and only one of the render blocks will be included in the final document output. If the user selects the true checkbox the document will only render for true and vice versa.

<!--RENDER='{{!Contact.Checkbox__c}}'== 'True' -->
This checkbox is checked.
<!--ENDRENDER-->
<!--RENDER='{{!Contact.Checkbox__c}}' == 'False' -->
This checkbox is unchecked.
<!--ENDRENDER-->

Basic Render and Nested Render Statements

S-Docs provides for 4 levels of nesting render statements. This allows you to place conditions within other conditions. Using nested render statements can also be leveraged to achieve compound logic as shown in the example below:

<!--RENDER='{{!Contact.Phone}}'== 'NULL' -->
  We don't have a primary phone number
  <!--RENDER1='{{!Contact.OtherPhone}}'== 'NULL' -->
  <!--RENDER2='{{!Contact.homephone}}'== 'NULL' -->
  and there are no alternate phone numbers available
  <!--ENDRENDER2-->
  <!--ENDRENDER1-->
  <!--RENDER1='{{!Contact.fax}}'!= 'NULL' -->
  but, there is a fax number: {{!contact.fax}}
  <!--ENDRENDER1-->
  for this contact!
  <!--ENDRENDER-->

There is no limit on the number of render statements you place within other render statements, however you are limited to nesting them to a maximum of 4 levels deep. Note in the example above that you can have multiple "Render1" tags within the same parent "Render" tag. However, you must change the render tag name whenever you are nesting a render within another render statement. When doing this, you must change the name of the nested render tag to "RENDER1" "RENDER2" or "RENDER3" and this name must be different than any of its parent tags.

Note: Nested render statements cannot skip levels. In other words, RENDER2 cannot come after RENDER; you must follow the RENDER > RENDER1 > RENDER2 > RENDER3 format.
Note 2: Whenever using the S-Docs Render feature, all of your RENDER and ENDRENDER tags must be properly paired and terminated.
Note 3: HTML tags must either fully enclose or be fully enclosed by RENDER and ENDRENDER statements. For example, a <table> tag cannot open outside of a render statement and close inside of one.

Basic Render Without Nesting

S-Docs also uses AND (&&) and OR (||)  in the RENDER statement, so you don't have to nest. A RENDER statement using AND (&&) can be leveraged to achieve logic as shown in the example below:

<!--RENDER=('{{!Contact.Phone}}' == '4150000000' && '{{!Contact.fax}}' != '4150000000') -->
We have the defined primary phone number, (415)000-0000, and a fax number that is different than the primary phone number
<!--ENDRENDER-->

Similarly, OR (||) can be used as shown in the example below:

<!--RENDER=('{{!Account.billingstate}}' == 'CA' || '{{!Account.shippingState}}' == 'CA') -->
Either the billing address or shipping address is in California
<!--ENDRENDER-->

AND (&&) and OR (||) can be used concatenate multiple statements. For example:

<!--RENDER=('{{!Contact.Phone}}' == '4150000000' && '{{!Contact.fax}}' != '4150000000') || ('{{!Contact.Phone}}' != '4150000000' && '{{!Contact.fax}}' == '[undefined]') -->
We have either a defined primary phone number, (415)000-0000, and a fax number that is different than the primary phone number, OR a primary phone number, (415)000-0000, and an undefined fax number
<!--ENDRENDER-->

A similar method using the Runtime Prompt can also show a prompt by letting the user choose to include or to not include the block of text.

'CONTAINS' and 'NOT CONTAINS' Statements

In addition to checking for a string with boolean functions, you can use 'CONTAINS' or 'NOT CONTAINS' to look for a specific string. For example, a statement with 'CONTAINS' would look like:

<!--RENDER='{{!Contact.Name}}' CONTAINS 'Tim' -->
Checking for the substring/contact name 'Tim'
<!--ENDRENDER-->

And a statement with 'NOT CONTAINS' would look like:

<!--RENDER='{{!Contact.Name}}' NOT CONTAINS 'Tim' -->
Checking for a substring/contact name other than 'Tim'
<!--ENDRENDER-->

Tags:

Was this helpful?