Add an Einstein Discovery Story to a CRM Analytics Template

Einstein Discovery stories can be added to an app template by referring to the story in the template-info.json file.

Create the Story 

Before adding the story to a template, create it using Einstein Discovery. (See Create a Story.) We recommend testing your story in CRM Analytics Studio before adding it to a template. Also, add the story JSON to the template. See the following section “Configure a Story” for instructions about editing the story JSON dynamically with a template rule.

Templates only support Einstein Discovery stories with a numeric, binary, and multiclass analysis prediction types in the outcome. The count analysis prediction type isn’t supported.

Note

Reference the Story in template-info.json 

To include the story in the template, add the following to template-info.json:

1"extendedTypes":{
2  "discoveryStories": [
3    {
4      "label": "AcquiredAccounts",
5      "name": "acquired_accounts",
6      "file": "acquired-accounts-story.json"
7      "condition" : "${Variables.StringValueInclude == 'Yes'}"
8    },
9    {
10      "label": "AcquiredAccounts2",
11      "name": "acquired_accounts2",
12      "file": "acquired-accounts-story2.json"
13    }
14  ]
15}

To add multiple stories to a template, add a discoveryStories entry for each story.

Add a conditional to exclude or include the story based on a variable the user selects in the wizard, available org data, or some other condition.

Story Metadata Examples 

Here’s an example acquired-accounts-story.json file for a story with a non-Boolean outcome.

1{
2    "outcome": {
3        "type": "Number",
4        "label": "CLV",
5        "name": "CLV",
6        "goal": "Maximize"
7    },
8    "autopilot": {
9        "enabled": true
10    },
11    "setup": {
12        "dataset": {
13            "id": "${App.Datasets.opportunities.Id}"
14        },
15        "outcome": {
16            "type": "Number",
17            "label": "CLV",
18            "name": "CLV",
19            "goal": "Maximize"
20        },
21        "fields": [{
22                "type": "text",
23                "name": "Account Id"
24            },
25            {
26                "type": "text",
27                "name": "BillingState"
28            },
29            {
30                "type": "date",
31                "name": "StartDate"
32            },
33            {
34                "type": "number",
35                "name": "example"
36            }
37            ...
38        ]
39    }
40}

For a boolean outcome, use something like the following:

1"outcome": {
2     "failureValue": "False",
3     "goal": "Maximize",
4     "label": "IsWon",
5     "name": "IsWon",
6     "successValue": "True",
7     "type": "Text"
8},
9"setup": {
10    "outcome": {
11        "type": "text",
12        "name": "IsWon",
13        "displayName": "IsWon",
14        "success": "True",
15        "failure": "False",
16        "goal": "Maximize"
17      },...
18}

Syntax notes:

  • The id value in dataset must match a dataset specified in template-info.json. You can only create one story per dataset in a template.
  • Story metadata is case-sensitive. Capitalize the first letter in outcome, and use lowercase for fields.
  • All fields are required in the outcome object.
  • outcome and setup.outcome must be the same.
  • The outcome name is the variable we want the story to identify. For example, in the above, we want to learn if the outcome is IsWon.
  • Number of fields can be a minimum of 2 and maximum of 50
  • Fields are the columns of data analyzed by Einstein Discovery and included in the story.
  • The autopilot object is optional. The default value is false.

Configure a Story 

You can add filters to fields in the story. In the following example, we only consider rows where IsClosed = true.

1"fields": [
2    {
3       "type": "text",
4       "name": "IsClosed",
5       "includeOther": false,
6       "values":
7       [
8         {
9           "name" : "true",
10           "ignored":false
11         },
12         {
13           "name" : "false",
14           "ignored":true
15          }
16       ]
17    }
18]

Use caution when adding date fields. Adding a field that shows individual dates (for example, 2019-07-01), isn’t helpful in the story. Instead, it makes more sense to show months.

1{
2    "type": "date",
3    "name": "CloseDate",
4    "periodicIntervals": [
5        "MONTH_OF_YEAR"
6    ],
7    "interval": "NONE"
8}

Multivalue fields can’t be included in a story. They’re excluded from the list in the story UI and must not be added to the story json.

Create or alter the story JSON using template rules. For example, the following rule loops through a measures variable and adds each field to the story JSON:

1{
2  "condition": "${!empty(Variables.Dataset_Measures[0].fieldName)}",
3  "action": "set",
4  "description": "put selected fields in ED Story json",
5  "path": "$.setup.fields",
6  "value": "${array:union(Rules.CurrentNode, array:forEach(Variables.Dataset_Measures,'{\"type\":\"number\", \"name\": \"${var.fieldName}\"}'))}"
7}

Here’s a rule that conditionally adds a competitor name if it’s selected in the wizard:

1{
2  "condition": "${!empty(Variables.Competitor.fieldName)}",
3  "type": "text",
4  "name": "${Variables.Competitor.fieldName}"
5}

Here’s another that adds only month of the year values to the story:

1{
2  "condition": "${!empty(Variables.Dataset_Dates[0].dateAlias)}",
3  "action": "set",
4  "description": "put selected fields in ED Story json",
5  "path": "$.setup.fields",
6  "value": "${array:union(Rules.CurrentNode, array:forEach(Variables.Dataset_Dates,'{\"type\":\"date\", \"name\": \"${var.dateAlias}\", \"periodicIntervals\": [\"MONTH_OF_YEAR\"], \"interval\": \"NONE\"}'))}"
7}