Skip to main content
Build the future with Agentforce at TDX in San Francisco or on Salesforce+ on March 5–6. Register now.

Prepare OmniScript JSON with Different Conditional Inputs

Learning Objectives

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

  • Describe how to save data based on different conditional inputs.
  • Prepare OmniScript JSON to use as input for Data Mapper Loads.

Save Data Based on Different Conditional Inputs

Let’s say that you have a guided interaction based on user input like the one in the OmniScripts with Branching module. In the Update Account Primary Contact OmniScript, the user can update the data for the existing primary contact, change the primary contact to another existing contact, or create a new contact and assign them as the primary contact. In other words, there are three potential ways or branches to update the data. 

  • Branch One: Update the existing primary contact’s email address or phone number.
  • Branch Two: Change the name of the primary contact and change the updated contact’s email address and phone number.
  • Branch Three: Enter the name, email address, and phone number of a new contact and make them the primary contact.

How do you make sure that data updates are saved no matter what option the end user chooses?

If you completed the OmniStudio Data Mappers module, you already know that a Data Mapper Load saves updates from the OmniScript back to Salesforce. A Data Mapper Load updates records with changed data and also creates new records at the same time. In this case, however, you actually need to build three of them. 

  • You need a Data Mapper Load that saves data for each branch of the OmniScript. You need to build an Integration Procedure to determine which Data Mapper Load is executed.
  • You need the full data JavaScript Object Notation (JSON) for all the three branches to build your Data Mapper Loads.

Prepare OmniScript JSON to Use as Input for Data Mapper Loads

When you use Preview to run an OmniScript, it builds a Data JSON populated with the data required for the interaction. The OmniScript JSON is in the Request Data pane of the OmniScript’s Action Debugger. This OmniScript JSON is what you use as input JSON for the Data Mapper Load. 

When you run an OmniScript with conditional outcomes, the JSON for only one of the outcomes populates. Because you need the full data JSON for all three outcomes to build your Data Mapper Loads, step through the OmniScript to populate the JSON with each of the conditional inputs.

Let’s explore how you do this for the Update Account Primary Contact OmniScript. 

OmniScript JSON for Update Primary Contact displays in the Request Data pane

In the Preview tab, enter an AccountIdas the ContextId. You need to select Update primary contact and then click Next.

In the OmniScript’s Action Debugger (1), expand IPSavePriContactDetails (2) and copy all of the data in the Request Data pane (3).

Note that the BlkChangePriContact data and BlkCreatePriContact data both have null values (4) in the text box. We come back to this in a moment.

The process is the same for the other two options in the OmniScript, although you don’t copy all of the JSON in the Request Data pane. Instead, copy only the JSON you need to replace the null values for the BlkChangePriContact data and BlkCreatePriContact data.

Here’s how to display the JSON for the Change primary contact option. 

  • Select and copy the BlkChangePriContact data in the text box. Be sure to include the four brackets, as shown in the highlighted portion of the image.

OmniScript JSON for Change Primary Contact displays in the Request Data pane.

Here’s how to display the JSON for the Create a new primary contact option. 

  • Select and copy the BlkCreatePriContact data in the text box. Be sure to include the two brackets, as shown in the highlighted portion of the image.

OmniScript JSON for Create a Primary Contact displays in the Request Data pane.

Go back to the JSON for the Update primary contact option and replace the null values for the BlkChangePriContact data and BlkCreatePriContact data with the JSON you copied for the Change primary contact and Create a new primary contact option. 

Full JSON Path

Now you have the full JSON path to build three new Data Mapper Loads. Before you build them, you need to prepare the Integration Procedure that connects them to the OmniScript. Let’s tackle all this in the next unit.

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