Conditionally Show Field Values on a Document

Introduction

If you need to conditionally show or hide certain field values on your documents, S-Docs has you covered; this document will explain this simple process.

To explain this feature, let's assume we're building an S-Docs template for a sales quote. In this quote, we would like to waive charges for a particular product if the customer is "Gold" tier; that is, if their tier is equal to Gold, we don't want a charge to be displayed; otherwise, the charge should be displayed. This is a common request and there are several options.

For More Information on Conditional Logic Within a Template

Option 1: Salesforce Formula Fields

Use a Salesforce Formula Field. To accomplish this you should simply create a formula field on the Salesforce object for your template that does all the work for you. You then drop that formula field into your S-Docs template.

For example, you could create the following Salesforce formula field on your base object:

IF( Tier__c=’Gold’, 'No Charge', Fee__c)

If the Customer’s Tier is Gold, then the text ‘No Charge’ would appear; otherwise the Fee would be displayed. You would then just insert this new formula field into you S-Docs Template using the template editor’s Insert Field button, just like any other merge field.

Alternatively, if your output format is MS Excel, you have the option of using an Excel Formula.

Option 2: The S-Docs Render Feature

Leverage the S-Docs RENDER feature. S-Docs provides a RENDER feature that will evaluate an expression, and if it is true, will display all of the content until the ENDRENDER tag is found. You can use the Insert Conditional Logic button to utilize this feature, or write the statements yourself. The example below shows how to meet the same requirement above. ‘No Charge’ will be displayed for Gold tier, and the Fee will be displayed for all other Tiers. Note the use of two equals (==) vs not equals (!=) as the comparator.

<!--RENDER='{{!CustomObject__c.Tier__c}}'==’Gold’ -->
    No Charge
    <!--ENDRENDER-->
    <!--RENDER='{{!CustomObject__c.Tier__c}}'!='Gold' -->
    {{! CustomObject__c.Fee__c}}
    <!--ENDRENDER-->

Here is an example to insert a paragraph under a conditional statement.

<!--RENDER='{{!Opportunity.Account.ShippingState}}'=='CA' -->
    Pursuant to California Code Section 2930-2935, the ARD administers the program through a primary contractor, currently
    ...
    <!--ENDRENDER-->

Important considerations when using the RENDER feature:

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
  1. It currently supports ==,!=, >, <, =>, =<, CONTAINS, and NOT CONTAINS for the comparison operator.
  2. The right hand side can contain a field value or a hard-coded value:  e.g.
<!--RENDER='{{!Contact.Language__c}}'=='French'-->
    Bonjour {{!Contact.firstname}},
    <!--ENDRENDER-->

OR,

<!--RENDER='{{!Account.Owner.name}}'=='{{!Username}}'-->
    You own this account.
    <!—ENDRENDER-->

3. You can use a check box field (Boolean) without an operator if you are checking if it is checked (true), e.g.

<!--RENDER='{{!Account.IsGoldCheckBox__c}}'-->
    Contact me at {{!Account.owner.phone}} if you have questions
    <!—ENDRENDER-->

But if you want to check if it’s unchecked (false) you need to specify an operator.

<!--RENDER='{{!CustomObject__c.IsGoldCheckBox__c}}' == 'false'-->
    Contact us at service@sdocs.com if you have questions
    <!—ENDRENDER-->

There is no limit on the number of Render statements you can have on a template, but each must be terminated by its own ENDRENDER tag (<!—ENDRENDER-->) 

Discussion

If you have only a few conditional statements, leveraging Salesforce’s formula fields (Option 1) provides a simple, powerful and familiar way to handle conditional data within S-Docs without adding complexity or having to learn any specialized syntax.

However, you may not want to alter your schema, because your organization has schema-level change restrictions, or perhaps you need to create too many formula fields just to handle document generation. You therefore have the option of handling this requirement within the S-Docs template as shown in Option 2.

Tags:

Was this helpful?