Saturday, April 20, 2024
No menu items!
HomeData IntegrationBuild dynamic content with Message Templates

Build dynamic content with Message Templates

Read Time: 4 minutes

When building automations, you often need to take a complex data structure and boil it down to a single text document. One obvious example of this type of transformation is mass personalized emails. An email platform takes semi-structured data about a customer — first and last name, title, contact info, recent purchases — and generates a personalized document. It seems simple, but to do this, you need a template that can apply conditional logic to make decisions. For example:

Start the email with “Hi Jim!” if the first name is known, or “Hi there!” if it isn’t.
Include a summary of a recent purchase which might be a single product, or a dozen.
Advertise an in-person event based on the customer’s location.

It’s not just marketing emails, though. Any time you need to turn a complex data model into something a human can easily understand, a templating tool can help. For another example, let’s revisit our most recent tutorial on custom actions. In that scenario, we captured leads from a webinar and created them in Salesforce. We also created a custom field in Salesforce to capture any questions the prospect asked during the webinar:

It looks easy, but let’s have a closer look at the data we’re working with:

It’s lists within lists! A prospect might ask any number of questions, or none at all. In turn, each question can have more than one answer. To store this information in Salesforce, we need to transform it into a single, human-readable block of text.

Let’s look at how to tackle this using Workato’s Message Templates feature.

Create a template

First we find the Message Templates page in the left nav under Tools and click New Template:

The template has two parts: an input and the template body.

The input is defined as a JSON schema. If you’re not comfortable writing JSON, you can often get started by copying a sample from a test job. In this case, the output of our Get questions from session action matches the input we need for the template.

First paste the sample into the wizard:

Optionally, we can clean it up a little to remove fields that we won’t need and make some names more readable:

Now that we’ve defined the input, we need to write the template. We want each question to look something like this:


What’s the best Halloween candy?


Reece’s Peanut Butter Cups, obviously!
Answered by Larry

Snickers bar. Full size, or nothing.
Answered by Moe

Message templates use a standard templating language called Mustache that lets us use variables and conditional logic to create the document. You can read the full docs for Mustache here.

We start by defining a block that we want to repeat for each question in our questions list:

The template outputs plain text, so you can use it to create documents formatted in markdown, HTML, etc. The Salesforce field we’ll eventually map this document to accepts HTML tags, so we’ll use those to format our message. We’ll start with the question. To include a variable from our input, place it in the template surrounded with double curly braces like {{this}}:

Remember that each question can have more than one answer, so we need to nest another repeating block inside the main one to build out each answer:

Use a template in a recipe

Our template is now complete! To use it in our recipe, we can use the Message Templates by Workato app:

Find the correct template in the picklist:

Map the correct datapills to the template’s input:

The output of this action is a single document we can map to the Webinar Questions field in Salesforce:


Our message template lets us map our list of webinar questions down to a single document. It works no matter how many questions are in the list, and no matter how many answers each question has!

The post Build dynamic content with Message Templates appeared first on Workato Product Hub.

Read MoreWorkato Product Hub



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments