Objective:
In this article we will cover how to build S-docs Templates for the following 2 common scenarios :
- Our customers need to output highly customized PDF documents with Youreka Questions and Answers pulled into multi row/column tables.
- Our customers need to output Youreka Questions and Answers as formatted 2-column tables which are not customizable.
Before you get started:
These articles might be helpful before you read this one:
Scenario 1 : How to generate customized PDF documents using S-docs
- Create the SDoc Template
Highly customized S-doc Templates can be built either manually within the SDoc Template editor by inserting tables or by using S-docs PDF Upload feature. Let’s first look at the PDF Upload feature.
The S-docs PDF Upload feature can be used when you have a PDF file with the Questions that need to be on the output PDF.
The first step for using the S-docs PDF Upload feature is to add PDF-UPLOAD as picklist value under the Template Format field. To do this, navigate to the SDoc Template object -> Fields & Relationships -> Template Format field -> Add a new value PDF-UPLOAD. For more information refer : Using PDF-Upload
You can now build your PDF-Upload S-docs Template. Create a new SDoc Template with Template Format set to PDF-UPLOAD. Provide a Template Name and select Related To Type as disco__Form__c. Navigate to the SDoc Template Editor. Within the Template Editor you will see the Upload PDF File option. Select the PDF File to automatically generate the SDoc Template tables.
- With the S-docs Template tables built, the next step is to set up the apex class that needs to be referenced within the S-docs Template.**
**Please contact your CSM for this apex class.
- Add callable apex to the SDoc Template.
- For the PDF-Upload format SDoc Template : Within the SDoc Template Editor navigate to the PDF-Upload Settings tab and add the below code to the Named Queries input box :
<!--{{!<callable><class>SDMapQuestionToAnswer1</class><action>getQuestionAndAnswerMap</action><args>{ "recordId" : "{{!disco__Form__c.Id}}" }</args></callable>}} -->
- For the PDF format SDoc Template : Within the SDoc Template Editor select Source and add the below code :
<!--{{!<callable><class>SDMapQuestionToAnswer1</class><action>getQuestionAndAnswerMap</action><args>{ "recordId" : "{{!disco__Form__c.Id}}" }</args></callable>}} -->
- For the PDF-Upload format SDoc Template : Within the SDoc Template Editor navigate to the PDF-Upload Settings tab and add the below code to the Named Queries input box :
- The final step is to set up merge fields to pull in Youreka Answers into the S-docs PDF.
To set up the merge fields we use the RandomId field on the Question Object as the unique identifier for each Question within the Youreka Template. Consider creating a Salesforce report of type Questions with Form Template to quickly identify the RandomId for each Question on your Youreka Template.
- For the PDF-Upload format SDoc Template : Within the SDoc Template Editor, In the PDF-Upload Fields tab click Create Another Field. Type defaults to Merge Field, copy/paste the Youreka Questions RandomId value into Merge Field in the following format {{!RandomId}} (example. {{!d6pt7k1r}}) and drag/drop the field that S-docs generates into the table cell where the Youreka Answer needs to appear.
- For the PDF format S-docs Template : Within the SDoc Template Editor’s Template Body tab, Copy/paste the Youreka Questions RandomId value directly into the table cell where the Youreka Answer needs to appear in the following format {{!RandomId}} (example. {{!d6pt7k1r}}).
Videos
S docs PDF upload + callable apex
S docs tables + callable apex
Scenario 2: How to generate PDF documents with Youreka Questions and Answers appearing as formatted 2-column tables using S-docs.
- Create the SDoc Template. Provide the Template Name, set Related To Type to disco__Form__c and set Template Format to PDF. We do not need to create the table structure within the SDoc Template since the tables are created during document generation.
- With the SDoc Template created, the next step is to set up the apex class** that needs to be referenced within the SDoc Template.
**Please contact your CSM for this apex class.
- Add callable apex and stylization to the SDoc Template
-
- Navigate to the SDoc Template Editor. In the Template Body tab, Click Source and add the following callable apex code :
<!--
{{!
<callable>
<class>CallableYourekaSDocsTable</class>
<action>getAnswers</action>
<args>{"returnAsTable":"true",
"formId": "{{!disco__Form__c.id}}",
"formLookupName":"",
"recordId":"",
"templateName":"",
"tableCSSName":"answerTable",
"createTableTag":"true",
"includeContentImages":"true",
"includePhotosInline":"true",
"contentImagesOnly":"false",
"photosOnly":"false",
"radioButtonsAsColumn":"false",
"sectionName":"",
"skipSpaces":"",
"linkedSectionAsTable":"true",
"queryWhereClause":"",
"hTMLName":"TABLE_HTML1"}
</args>
</callable>
}}-->{{!TABLE_HTML1}}
- Navigate to the SDoc Template Editor. In the Template Body tab, Click Source and add the following callable apex code :
- Within the Template Body’s Source add the following stylization at the top:
<style type="text/css">img {
width: 200px;
}
.answerTableRowEven{border:solid black 1px !important;}
.answerTableRowOdd{border:solid black 1px !important;}
.answerTable {
width:100%;
font-family:arial unicode ms,sans-serif;
font-size:12pt;
border: 1px solid black;
text-align:center;
page-break-inside: avoid !important; page-break-before: auto !important;
}
.answerTable td{
border: 1px solid black;
font-family:arial unicode ms,sans-serif;
font-size:12pt;
text-align:center;
}
</style> - Following are the parameters passed to the callable apex:
formId
If S-doc Template is related to Youreka Form Object we can pass the Form ID directly through merge field : {{!disco__Form__c.Id}}
recordId, templateName, formLookupName
If the S-doc Template is not related to Youreka Form Object, we pass these 3 attributes.
- formLookupName is the API name of lookup relationship Field from the Form Object to the Object that the S-doc Template is related to. Example. If the S-doc Template is related to WorkOrder and the lookup from Form to Work Order is Work_Order__c, this field value would be Work_Order__c.
- recordId is the merge field for the Object that the S-doc Template is related to. In the above example it would be {{!WorkOrder.id}}
- templateName is the Youreka Form Template Name of the Form from which the Answers need to be pulled into the S-docs PDF.
tableCSSName tableCSSName is the reference to the style sheet. In the style sheet provided above it would answerTable.
createTableTag createTableTag will always be set to TRUE
includeContentImages Set to TRUE if there are Content type Images present on the Youreka Form that need to be displayed on the PDF
includePhotosInline Set to TRUE to include Photos within the same section that they appear on Form.
includeContentImages and includePhotosInline can be set to False and then the callable apex can be repeated with PhotosOnly / ContentImagesOnly set to TRUE so that these appear at the bottom of PDF.contentImagesOnly Set to TRUE to include only Content type Images present on the Youreka Form on the PDF. photosOnly Set to TRUE to include only Youreka Photos captured on the PDF. radioButtonsAsColumn Set to TRUE to display Radio button answers as separate table columns on the PDF. sectionName sectionName can contain the name of the Youreka Form Template Section to target specific sections of the Form Template. skipSpaces skipSpaces can be set to TRUE to skip Content type Spaces added to the Youreka Form. linkedSectionAsTable Set to TRUE to display Youreka Form Linked Section records in a table format. queryWhereClause queryWhereClause can be used to add additional filters to the PDF output hTMLName hTMLName is the name of the table. In the above example it is table1.
This attribute can be used to repeat the callable apex multiple times with different table names.
-
Videos
S docs 2 columns using callable apex
Relevant S-docs KB articles
- S-docs Template Editor
https://kb.sdocs.com/knowledge-base/sdocs/creating-templates/overview-the-s-docs-template-editor/ - Setting up S-docs with custom Objects like Youreka Forms
https://kb.sdocs.com/knowledge-base/sdocs/general-configuration/configure-sdocs-with-custom-objects-salesforce-lightning/ - S-docs PDF upload
https://kb.sdocs.com/knowledge-base/sdocs/creating-templates/pdf-upload/#:~:text=To%20access%20the%20PDF%2DUpload%20feature%2C%20you'll%20need,on%20the%20Template%20Format%20field
Comments
0 comments
Please sign in to leave a comment.