Thursday, December 22, 2022

OmniStudio in Salesforce

In this article, we’ll dive into what OmniStudio is, its components and its use cases, as well as a hand-on tutorial. The tutorial will show how to retrieve account information for an existing account and display it to the user. 

OmniStudio Overview

OmniStudio comprizes four main components:

FlexCards

FlexCards provide at-a-glance information and access to relevant tasks for your customers. These components can provide easy-to-use beginning and ending points for customer transactions by summarizing all the pertinent information for a given transaction in one place. 

Using the drag-and-drop builder, designers can create layouts and style data from multiple sources for use on any device or channel. FlexCards are repeatable, allowing you to display multiple records of data in a consistent series of stylized cards. You can also embed FlexCards inside OmniScripts to provide contextual information or execute sub processes for users as they make their way through its steps. 

A few excellent use cases for FlexCards:

  • Displaying policy information for an insurance customer with actions to Pay Premiums, Modify Coverage, or File a Claim.
  • Displaying a list of medical plans the user can compare before selecting one as part of an interaction.
  • Displaying weather information, including the 7-day forecast.

OmniScripts

An OmniScript is a guided experience that takes users through complex business processes. Using its drag-and-drop editor, application builders can design seamless customer experiences across industries. 

It sets itself apart from flows by offering greater flexibility and more styling options creating a more modern, branded look and feel. Within an OmniScript, designers can choose from several diverse types of elements to build their script. Designers can:

  • Call actions such as saving data and sending an email.
  • Display text and images to enhance usability and UI.
  • Perform calculations and show conditional messages and errors using pre-configured functions.
  • Capture key information as part of the experience using inputs.
  • Insert other OmniScripts to create reusable, composable workflows.

Here are a few excellent use cases for OmniScripts:

  • Guide citizens through an application process.
  • Guide customers through a selling process, such as selecting an insurance policy.
  • Guide users through a self-service process.

DataRaptors

A DataRaptor is a declarative mapping tool that enables you to read, edit, and transform data in Salesforce. It enables admins to display and save data without the need to write any Apex. DataRaptors act as the main way to manipulate data in OmniStudio. 

There are four types of DataRaptors:

  1. Turbo Extract: Rapidly retrieves data from a single Salesforce Object.
  2. Extract: Retrieves data from one or more Salesforce Objects.
  3. Load: Saves data to one or more Salesforce Objects.
  4. Transform: Manipulates data provided from Salesforce or external sources.

DataRaptors work primarily with JSON, but also support XML and Custom Schemas. They can also leverage OmniStudio-specific functions and formulas to provide more flexibility when transforming data.

Integration Procedures

Integration Procedures are processes that are used to read and edit data from Salesforce or from external applications. These server-side applications allow designers to build complex data transformations without writing any code. 

Integration Procedures can provide data to both internal sources such as FlexCards, OmniScripts, and SObjects, and to external sources including APIs, email, and DocuSign. Because Integration Procedures are created through configuration, they are easier to maintain and quicker to develop than their Apex counterparts.

Each of these tools offers unique capabilities that, when combined, elevate your user workflows beyond what flows alone can offer. As Salesforce continues to expand the capabilities within OmniStudio, there has never been a better time to learn it!

Getting Started With OmniStudio

You can sign up for your very own OmniStudio enabled developer org here.

This org is good for 180 days and features a fully enabled set of OmniStudio licenses. Once you have logged in, open the App Launcher, then open the OmniStudio app. Now that you’re set up, let’s walk through creating a simple DataRaptor and OmniScript that will display account information to a user. Let’s get building! 

Create a New OmniScript

  • Once you open the OmniStudio console app, click on the dropdown menu to see four familiar options: OmniScripts, FlexCards, DataRaptors, and Integration Procedures.
  • If it is not already selected, click OmniScripts.
  • You will be greeted with a list view of sample OmniScripts, which you can review later. For now, click on the New button on the top-right corner of the page.

OmniScripts utilizes the Type, SubType, and Language fields to give them a unique identity. No two OmniScripts can have the Same Type, SubType, and Language in the same org. These fields also provide a mechanism for classifying and organizing your OmniScripts.

  1. Set the fields like the image above:
  • Name = updateAccountDetails
  • Language = English
  • Type = update
  • SubType = accountDetails

Once you finish, click save.

Now that we’ve created a new OmniScript, let’s take a tour of the builder.

Understanding the OmniScript Creation Process

The canvas is your WIWIG (What You See is What You Get) drag-and-drop editor for OmniScripts. Any action, function, or step (screen) you’d like to have occur is dropped into this canvas. Elements are executed from top to bottom sequentially.

The Build Panel contains all the elements available to use in your OmniScript: 

  • Action elements such as sending an email, saving/retrieving a record, and making callouts to external services.
  • Display elements (such as Steps) with which the user will interact. These are similar to Flow Screens.
  • Input elements such as text or phone number and select list fields with which a user can enter data.

Add Fields to Your OmniScript

  • In the side panel, expand the INPUTS section.
  • Find the Text element and drag it onto the Step1 step in the canvas. We will use this to represent the Name field on the Account.

Note: You may need to expand Step1 if you have trouble dragging the text element into it. If you’ve done it correctly, it should look like this image.

In the Properties Panel for the Text element change the default values. If the Properties Panel does not appear, click on the text element in the canvas:

  • Name = Name
  • Field Label = Name

Note that the field label can be set to any value, but the Name field will need to be unique across the entire OmniScript. For Instance, if we named the field Account Name, no other element in the OmniScript could be named Account Name.

Repeat the steps above to add a Phone element underneath Name:

  • Name = Phone
  • Field Label = Phone

 In the Build Panel, drag a Select Element below the Phone element:

  • Name = Type
  • Field Label = Type

The select element is unique as it allows you to pull select values from any selected field on an SObject. Let’s set it up to pull values from the Type field on the Account Object.

  • Option Source = SObject
  • Source = Account Type

Select elements also allow you to pull custom values from Apex (via the Velocity Interface Class) or set up values manually.

Now that we’ve added all the fields, let’s rename the step to something that better reflects its new fields.

  1. Click on the Step1 Step element
  2. Set the following values:
  • Name = AccountDetails
  • Field Label = Account Details

Add a DataRaptor to Pull Data into the OmniScript

Now that we have fields, add data in to test it.

  • In the Build Panel, expand the ACTIONS section.
  • Drag the DataRaptor Extract action onto the canvas above the AccountDetails Step. This will ensure that we load data before showing the user the screen.

In the Properties Panel for the DataRaptor, set the following values:

  • Name = drExtractAccountDetails
  • Label = Fetch Account Details

Finally:

  • Underneath the DataRaptor Interface field, click + Create New DataRaptor
  • Enter the name drExtractAccountDetails into the popup and click OK

This will launch a new console tab for your new DataRaptor.

Set Up a DataRaptor

  • In the DataRaptor, on the EXTRACT tab, click the + Add Extract Step button. This will present a list of all SObjects available to query. 
  • Choose Account from the list.
  • Set the Extract Output Path to Account.
  • Set the Filter to Id = ContextId. This will pull back a single record where the Account ID is equal to the ContextId passed in from the OmniScript.

Note: The Extract Path can be set to any value. Think of it as a variable to reference the results of the extract.

In the filter we reference a value called ContextId. This is a special record ID passed into the DataRaptor from the OmniScript that allows for the DataRaptor to dynamically extract a record based on the value provided. In this example, we will be providing an Account Id as the ContextId. More on that later.

Map the Extracted Data

Now that we’ve extracted the Account record, let’s map its fields for use in our OmniScript.

  1. Click the OUTPUT tab.
  2. Click the + button to the right of the OUTPUT JSON PATH header.
  3. Enter the following values:
  • Extract JSON Path = Account:Id
  • Output JSON Path = Account:Id

This tells the DataRaptor to return the Id from the account record to a JSON object called Account with a node called Id. On the right-hand side panel under Current JSON Output, you can see visually how this data will be structured.

We won’t do it in this exercise, but if you provide your expected output into the Expected JSON Output on the right-side panel, the Output JSON Path field will provide autocomplete based on what you’ve added.

Repeat this exercise for the Name, Phone and Type fields:

  • Extract JSON Path = Account:Name
  • Output JSON Path = Account:Name
  • Extract JSON Path = Account:Phone
  • Output JSON Path = Account:Phone
  • Extract JSON Path = Account:Type
  • Output JSON Path = Account:Type

When finished, your DataRaptor should look like the picture below:

Test Your DataRaptor Results

  1. Click on the PREVIEW Tab.
  2. In the Input Parameters Panel on the left, enter the following values:
  • Key = ContextId
  • Value = <ANY ACCOUNTID>

For best results, select an Account ID for an Account that has populated Type and Phone fields.

  •   Click the Execute button at the bottom of the Input Parameters panel.

You should see results comparable to the screenshot below:

The center Panel provides the results of the DataRaptor along with some useful information such as response time and APEX CPU usage. The Right panel shows the SOQL query that was executed as part of the extract and any error messages. This can be helpful to debug issues with more complex DataRaptors.

Putting It All Together

Now that your extract works, let’s tie it all together with the fields we added to the OmniScript we created initially:

  1. Navigate back to your OmniScript
  2. Click on the DataRaptor we just created in the canvas
  3. In the Properties Panel, set the following values within the Input Parameters section:
  4. Data Source = ContextId
  5. Filter Value = ContextId

The Filter value must match the value we set in the DataRaptor. For instance, if we had set Id = MyAccountId as the filter in the DataRaptor instead of id = ContextId we would need to set the Filter Value here in the OmniScript to MyAccountId.

Next, we need to transform the data coming from the DataRaptor so that it maps to our Step:

  1. Expand the RESPONSE TRANSFORMATION section of the Properties Panel
  2. Enter the following values:
  • Response JSON Path = Account
  • Response JSON Node = AccountDetails

The Response JSON Path tells the DataRaptor which node in the JSON response to return to the OmniScript. The Response JSON Node tells the DataRaptor which parent node name to give to the response data in the OmniScript. Since the node name now matches the step name (AccountDetails), the data should prepopulate the field data with the data from the DataRaptor.

Test It Out

  • Click the preview button at the top of the OmniScript builder.
  • At the top of the preview, in the ContextId input, enter the Account ID you used to test the DataRaptor and click the refresh button to the right.

You should now see the data from your Account populate in your OmniScript!

Congrats on completing your first OmniScript!

Summary

This tutorial just scratches the surface of the capabilities you can unleash with OmniScripts and DataRaptors. If you want to dig deeper, then be sure to check out the Get to Know OmniStudio trail on Trailhead for more hands-on exercises that cover the full breadth of OmniStudio.


https://trailhead.salesforce.com/content/learn/trails/get-to-know-omnistudio

No comments:

Post a Comment