Skip to main content

Explore Client-Side Document Generation

Learning Objectives

After completing this unit, you’ll be able to:

  • Explain three ways of passing data into a document template.
  • Describe elements of the client-side OmniScript sample.

Building Document-Generation Processes

You’ve seen Linda, our Salesforce administrator, create the perfect document templates for Candace and her team. 

Illustration of Linda building the document templates.

She built Microsoft Word and PowerPoint templates, inserting tokens in all the right places. She imported her templates into the Document Template Designer in Salesforce, defined the configuration, and tested the templates to ensure they work flawlessly. Now you might be wondering: How does she embed the document templates into a business process so that Candace’s team can use them? 

All documents in OmniStudio Document Generation are created by passing JSON input data into a template, which Linda created earlier. An OmniScript or custom class can provide the JSON input data, or the template can extract the data using the specified DataRaptors. 

  • Whenever a user interaction is required, for example, if a sales rep needs to fill out a form to generate a document, use the client-side document-generation processes.
  • If you want to automate the process, for example, to generate a document in response to a trigger, or if you have a large document, use server-side document generation.

Let’s dive deeper into client-side document generation.

Passing Data into a Document Template

You have three ways to pass data into your document template in client-side document generation. 

  • Customize the sample OmniScript provided.
  • Create a new OmniScript.
  • Use JSON input.

Customized Sample Client-Side OmniScript

OmniStudio Document Generation includes a sample OmniScript that generates documents. The OmniScript presents steps to collect necessary information, such as Object Id and document-formatting options. The last step provides a preview of the generated document for download. 

Sample Client-Side OmniScript preview.

The sample OmniScript is generic, so you can customize it to fit your use case. To use the sample with your document template, make sure your template has a DataRaptor Extract and a DataRaptor Transform because the OmniScript sample doesn’t extract Salesforce data for the document. You set the DataRaptors up in the previous unit using the Document Template Designer. 

User Data Collection with OmniScript

To generate documents, you can also use a separate OmniScript that collects user data to pass into the document template. For example, a car insurance policy OmniScript asks the customer for their name, birthdate, address, and car details. The OmniScript then passes the data into the template. Because the OmniScript already contains DataRaptors or Integration Procedures, the template only requires a DataRaptor Transform and not a DataRaptor Extract, like the previous example. 

Custom Class JSON Input 

For documents with lots of data, for example, more than 200 line items, you can use a custom Apex class to extract the data and generate the JSON input. This way, you don’t need an OmniScript or DataRaptor Extract. To use this method, connect your custom Apex class to the document template itself in the Document Template Designer. 

Document Generation OmniScript Sample

One of the easiest ways to get up to speed with OmniStudio Document Generation is to use the sample OmniScript. This is what Linda uses to create document-generation processes for the Cloud Kicks sales team. She uses the sample to test the template or as a starting point for building her own OmniScript. Then end users can launch the OmniScript from a record page to generate a document. 

Find the sample OmniScript in the OmniScript tab under the name docGenerationSample/fndSingleDocxLwc. 

Linda creates a new version of the sample OmniScript. She uses her version as the starting point for a new document-generation OmniScript. This way, the original sample OmniScript stays the same, so Linda can use the original sample to create other OmniScripts later on.

Let’s learn about the elements of the OmniScript sample and follow Linda as she customizes it for her use case. The sample client-side document generation OmniScript includes seven steps, which run sequentially when the OmniScript is invoked. 

Click the plus-icon (+) hot spots on the image to learn more.

Client-side document generation is a great option for business processes that require user interaction and for generating smaller documents. In the next unit, you learn about server-side document generation and all the goodness it has to offer.

Resources

Keep learning for
free!
Sign up for an account to continue.
What’s in it for you?
  • Get personalized recommendations for your career goals
  • Practice your skills with hands-on challenges and quizzes
  • Track and share your progress with employers
  • Connect to mentorship and career opportunities