Category

General Solutions

Use S-Docs with your custom object

By Documentation, General Solutions, S-Docs Cookbook No Comments

S-Docs works great with your custom objects, but there are a few configuration steps you will need to take.

Below, you will find an overview of the configuration steps. Detailed step-by-step instructions on how to configure S-Docs with your custom object are available here: Configuring S-Docs with Custom Objects.

First, you will need to add your custom object to the picklist value “Related to Type” field in the SDOC Template object. When adding your object, be sure to use your object’s API name (e.g. myObject__c) as the new picklist value. This step is critical, as it allows S-Docs templates to be associated to your custom object.

Second, you need to create an S-Docs button and place it on your custom object’s detail page. We’ve found that a Detail Page button displayed in the “existing window without sidebar or header” works great.

You should create a button link using a URL similar to the following, but replacing ‘myObject__c’ with your Custom Object API name:

{!URLFOR('/apex/SDOC__SDCreate1', null,[id=myObject__c.Id, Object='myObject__c'])}

Lastly, this step allows generated S-Docs to be associated to your custom object and further allows you to place an S-Docs related list on your custom object’s detail page layout. You simply need to add a look-up field to the SDOC Relationship object that points to your custom object.

Note: The “Field Name” of this new lookup field must match the name of your object (e.g. myObject) without the “__c.”

Discussion: When using S-Docs with custom objects, the field template designer will automatically correct and append your related object fields with a “__r.” If you are comfortable creating your templates in the source code, be sure to use the standard Salesforce conventions and dot notation and be mindful of capitalization differences.

Conditionally show a field value on a document

By Documentation, General Solutions, S-Docs Cookbook No Comments

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.

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:

[code lang="html"]IF( Tier__c=’Gold’, 'No Charge', Fee__c)[/code]

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 RENDER 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.

[code lang="html"]<!--RENDER='{{!CustomObject__c.Tier__c}}'==’Gold’ -->
No Charge
<!--ENDRENDER-->
<!--RENDER='{{!CustomObject__c.Tier__c}}'!='Gold' -->
{{! CustomObject__c.Fee__c}}
<!--ENDRENDER-->[/code]

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

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

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.

[code lang="html"]<!--RENDER='{{!Contact.Language__c}}'=='French'-->
Bonjour {{!Contact.firstname}},
<!--ENDRENDER-->[/code]

OR,

[code lang="html"]<!--RENDER='{{!Account.Owner.name}}'=='{{!Username}}'-->
You own this account.
<!—ENDRENDER-->[/code]

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

[code lang="html"]<!--RENDER='{{!Account.IsGoldCheckBox__c}}'-->
Contact me at {{!Account.owner.phone}} if you have questions
<!—ENDRENDER-->[/code]

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

[code lang="html"]<!--RENDER='{{!CustomObject__c.IsGoldCheckBox__c}}' == 'false'-->
Contact us at service@sdocs.com if you have questions
<!—ENDRENDER-->[/code]

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.

Top