Skip to main content
Join the Agentforce Hackathon on Nov. 18-19 to compete for a $20,000 Grand Prize. Sign up now. Terms apply.

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 Data Mappers. 

  • 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 Data Mapper Extract and a Data Mapper Transform because the OmniScript sample doesn’t extract Salesforce data for the document. You set the Data Mappers 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 Data Mappers or Integration Procedures, the template only requires a Data Mapper Transform and not a Data Mapper 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 Data Mapper 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

Share your Trailhead feedback over on Salesforce Help.

We'd love to hear about your experience with Trailhead - you can now access the new feedback form anytime from the Salesforce Help site.

Learn More Continue to Share Feedback