Objective:
After reading this article, you will understand how to setup S-Docs to generate PDFs of Youreka forms
Before you get started:
These articles might be helpful before you read this one:
Out of the box, Youreka provides you with the ability to produce PDFs of your forms with a single click. For most of our customers, this PDF generation capability is sufficient for their needs. With that said, there are situations where advanced document generation capabilities are required as part of an organization's forms process. Some examples of requirements might be:
- You are interested in customizing the look and feel of the PDF, including images, colors, format, and more.
- You are interested in have automation drive the document generation process.
In order to meet these requirements, we lean on document generation applications such as S-Docs to get the job done. S-Docs is easy to set up, maintain on an ongoing basis, and provides you with ultimate flexibility on how your documents will look after they are generated. The following article will teach you to to set up S-Docs in a Salesforce environment right alongside Youreka.
Step 1: Install and Set Up S-Docs
S-Docs can be found on the Salesforce AppExchange. Visit the listing and click "Get It Now" to install the package into your Salesforce environment.
Be sure to walk through all of the necessary steps after the package is installed, including setting up your product key, creating relationships between your desired objects and the S-Docs objects, and more. Their product documentation does a great job of walking you through the steps.
For Youreka specifically, because we're looking to create a button on the Youreka Form object that generates a PDF of any given form, here were some of the steps we took:
- We created a lookup to Form on the S-Docs Relationship object.
- Next, we added the S-Docs relationship related list to our Form Lightning Page layout, so that every time a document gets generated, we can view it on the Form page. If you have yet to create a Lightning Page for the Form object, we highly encourage you to do that now.
- Next, we added a lookup on the Form Template object to the S-Docs template object, and we called it "Custom PDF Settings". This step is optional, and definitely should only be done if the requirements exist for it. Essentially what this allows us to do is define, at the Form Template level, how each of the Forms for that template will look. This optional makes a lot more sense if you have a Lightning Page set up for the Form Template object. If you have not done this, we highly encourage you to do that now.
- We also created a formula field on the Form object that mirrors the ID of this "Custom PDF Settings" field. This will come in handy in the next step.
- Next, we created a button on the Form Object that launches S-Docs.
{!URLFOR('/apex/SDOC__SDCreate1', null,[id=disco__Form__c.Id, Object='disco__Form__c', doclist=disco__Form__c.Custom_PDF_Template__c, autoopen=1, sidebar=false, showHeader=false ])}
Every button will be different, based on certain requirements and desired behavior. Feel free to check out S-Doc's button documentation to learn more about how these buttons work. There are many parameters you can add to the button to change how it behaves.
Step 2: Create an S-Docs Template
At this point, we've set up S-Docs to work with the Form object. And we've made some configurations that will allow us to easily create a document when we want to as we view any form. Now, we need to decide exactly how we want our document to look when it gets generated, and that's where S-Doc templates come into play. Follow these steps to set up an S-Docs template:
- In the App Launcher, search for S-Docs Templates
- Create a new S-Docs template record. If you don't have disco__Form__c as an option for Related To Type, you will need to edit the picklist on this object to include it.
- After you create the template record, locate the Template Editor button in the top right corner of the record page. This allows you to access the editor for designing this template.
- From here, you can begin adding fields and formatting to your template. In the above example, you can see that we are adding the Form Template name, the form name, and some general information about the form.
- Below (not quite visible) are some related lists, which include perhaps the most important part of the document, the Questions and Answers for this form! Remember, for each Youreka Form, there are child Answer records storing the data that the form user input while completing the form. We will need to query these records in order to render them on the document.
This portion of the tutorial can get fairly tedious if it is your first time creating a document for Youreka. To offset that, we've put together quite a few resources to make it easier for you.
- Be sure to review the S-Docs Related Lists documentation to learn how this works.
- We've created a template that you can import into your environment. This template should work across Salesforce orgs. Review the S-Docs template import documentation, and then use the file attached to this knowledge base article, which you should easily be able to import.
- If you are looking to build your own template instead of importing ours, the following HTML snippets and SOQL queries should save you massive amounts of time.
S-Docs Source Code: Stylized Youreka Questions and Answers, grouped by Section. Excludes photos, e-signatures, free text, images, and linked sections.
<style type="“text">table.table335 {border:solid #BCBCBC 1px;font-family:Arial,sans-serif; font-size:10pt; width:100% }
.table335header {text-align:center;font-weight:bold;border:solid black 1px;color:#FFFFFF;background-color:#000000;}
.table335footer {text-align:right;font-weight:bold;border:solid black 1px; height: 30px}
.table335RowEven{border-left:solid black 1px; background: #EFEFEF;}
.table335RowOdd{border-left:solid black 1px; background: #FFFFFF;}
.table335col0{font-size:14pt;font-weight:bold;text-align:center; width: 100%; background: #6D3360; color: #fff;}
.table335col1{line-height:25px;padding-left:5px;padding-right:5px;border-right:solid #BCBCBC 1px;text-align:left;vertical-align:top; width: 50%;}
.table335col2{line-height:25px;padding-left:5px;padding-right:5px;border-right:solid #BCBCBC 1px;text-align:left;vertical-align:top; width: 50%;}
</style>
<table cellpadding="0" cellspacing="0" class="table335"><!--{{!
<lineitemsSOQL>
<class>table335</class>
<soql>Select disco__Question__r.disco__Section__r.Name, disco__Question__r.disco__label__c, disco__answer__c FROM disco__Answer__c WHERE disco__Form__c='{!ObjectID15}' AND disco__Question__r.disco__Type__c != 'Attachment/Photo' AND disco__Question__r.disco__Type__c != 'Free Text' AND disco__Question__r.disco__Type__c != 'Image' AND disco__Linked_Section_Order__c = NULL AND disco__Question__r.disco__Type__c != 'E-Signature' AND disco__Hidden_By_Dep__c = FALSE ORDER BY disco__Question__r.disco__Order__c, disco__Question__r.disco__Section__r.Name</soql>
<column>disco__Question__r.disco__Section__r.Name</column>
<column>disco__Question__r.disco__label__c</column>
<column>disco__answer__c</column>
<groupby>disco__Question__r.disco__Section__r.Name</groupby>
<groupby type='newtable'>disco__Question__r.disco__Section__r.Name</groupby>
<groupbyheader position="after-group">Question,Label</groupbyheader>
</lineitemsSOQL>
S-Docs Source Code: Stylized Section Header "Photos", querying all images related to the Form record
<style type="“text">table.phototable {border:solid #BCBCBC 1px; background: #707070; font-family:Arial,sans-serif; font-size:12pt; width:100% }
</style>
<table border="1" cellpadding="1" cellspacing="1" class="phototable" style="width: 625px;" width="500">
<tbody>
<tr>
<td style="text-align: center;"><span style="color:#FFFFFF;"><strong><span style="font-family:tahoma,geneva,sans-serif;">Photos</span></strong></span></td>
</tr>
</tbody>
</table>
<span style="font-size:11pt;"><span style="font-family:tahoma,geneva,sans-serif;"></span></span>
<div><!--{{!
<lineitemsSOQL><class>none</class>
<soql>select ContentDocument.latestpublishedversionid from contentdocumentlink where linkedentityid='{{!ObjectId15}}' AND (ContentDocument.FileExtension LIKE '%jpeg')
</soql>
<column prefix="<img src='/sfc/servlet.shepherd/version/download/" postfix="' width='200px' />">ContentDocument.latestpublishedversionid</column>
</lineitemsSOQL>
}}--></div>
Note: To include e-signatures in your PDF, you will want to enable the Save E-Sig as JPG custom setting. See how here.
Between the WISIWYG editor, the ability to edit source code, the ability to create complex SOQL queries, our importable template (see attached), and the code snippets above, you should have everything you need to build out a template that works for you.
Step 3 (Optional): Generate PDFs using Salesforce Automation
Using S-Docs, it's possible to use Salesforce automation to generate a document (and even send it to an email recipient). This is possible by creating an S-Docs Job record in Salesforce, using Process Builder, Flow, or Apex. When the S-Docs Job record is created, S-Docs runs the templates that you define! Here is an example of how it can look:
In the above example, a Youreka user checks a box on the form that indicates they wish to send the form, as an email and PDF, as soon as the form is submitted. In order to accomplish this, we configured the following items:
- Two fields on the Form object called "Send Email Upon Submit" and "Email To Address". The former is a checkbox, the latter is an email field.
- We utilized Self Field Links which allow you to have questions on Youreka's forms link to the Form record itself. The form template above has two final questions, "Would you like to email this form upon submission", and "Email Address" - both of which are field linked to the fields we created in the previous step.
- We built a process builder that triggers when a Form record is submitted, and those pieces of information are filled out. The process builder creates an S-Docs Job record, which drives the rest of the document generation process. You can learn more about S-Docs Jobs here.
- The process builder chooses two S-Docs templates, the PDF template, and an HTML template that facilitates the email send. The HTML email template is attached to this article, and can be imported into your Salesforce environment.
The final step is to test. Publish a form template that includes those two fields, and submit. Check to see if an S-Docs Job record successfully gets created.
After it is all built, you should now have an infrastructure that allows you to use Salesforce automation to automatically send PDFs of Youreka forms based on changes in the Salesforce environment.
Comments
0 comments
Please sign in to leave a comment.