---
schema_version: "1"
id: 44607456339f9e3b7dc4049a6d4d62a3f819428a1053fd3dd766c8dca195213b
title: Add an Einstein Discovery Story to a CRM Analytics Template
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/analytics/bi_dev_guide_wave_templates/guides/concept/bi-templatesdev-add-discovery-story.md
canonical_url: https://developer.salesforce.com/docs/analytics/bi-dev-guide-wave-templates/guide/bi-templatesdev-add-discovery-story.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 0cee5f3090b26e287e3fbaf30c22636841e29b603cc344ce02de643ca38cf832
products:
  - Analytics Templates Developer Guide
  - analytics
---

# 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](https://help.salesforce.com/articleView?id=bi_edd_create.htm&type=5).) 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.

**note:** 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.

## Reference the Story in template-info.json

To include the story in the template, add the following to `template-info.json`:

```nolang
"extendedTypes":{
  "discoveryStories": [
    {
      "label": "AcquiredAccounts",
      "name": "acquired_accounts",
      "file": "acquired-accounts-story.json"
      "condition" : "${Variables.StringValueInclude == 'Yes'}"
    },
    {
      "label": "AcquiredAccounts2",
      "name": "acquired_accounts2",
      "file": "acquired-accounts-story2.json"
    }
  ]
}
```

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.

```nolang
{
    "outcome": {
        "type": "Number",
        "label": "CLV",
        "name": "CLV",
        "goal": "Maximize"
    },
    "autopilot": {
        "enabled": true
    },
    "setup": {
        "dataset": {
            "id": "${App.Datasets.opportunities.Id}"
        },
        "outcome": {
            "type": "Number",
            "label": "CLV",
            "name": "CLV",
            "goal": "Maximize"
        },
        "fields": [{
                "type": "text",
                "name": "Account Id"
            },
            {
                "type": "text",
                "name": "BillingState"
            },
            {
                "type": "date",
                "name": "StartDate"
            },
            {
                "type": "number",
                "name": "example"
            }
            ...
        ]
    }
}
```

For a boolean outcome, use something like the following:

```nolang
"outcome": {
     "failureValue": "False",
     "goal": "Maximize",
     "label": "IsWon",
     "name": "IsWon",
     "successValue": "True",
     "type": "Text"
},
"setup": {
    "outcome": {
        "type": "text",
        "name": "IsWon",
        "displayName": "IsWon",
        "success": "True",
        "failure": "False",
        "goal": "Maximize"
      },...
}
```

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.

```nolang
"fields": [
    {
       "type": "text",
       "name": "IsClosed",
       "includeOther": false,
       "values":
       [
         {
           "name" : "true",
           "ignored":false
         },
         {
           "name" : "false",
           "ignored":true
          }
       ]
    }
]
```

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.

```nolang
{
    "type": "date",
    "name": "CloseDate",
    "periodicIntervals": [
        "MONTH_OF_YEAR"
    ],
    "interval": "NONE"
}
```

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:

```nolang
{
  "condition": "${!empty(Variables.Dataset_Measures[0].fieldName)}",
  "action": "set",
  "description": "put selected fields in ED Story json",
  "path": "$.setup.fields",
  "value": "${array:union(Rules.CurrentNode, array:forEach(Variables.Dataset_Measures,'{\"type\":\"number\", \"name\": \"${var.fieldName}\"}'))}"
}
```

Here’s a rule that conditionally adds a competitor name if it’s selected in the wizard:

```nolang
{
  "condition": "${!empty(Variables.Competitor.fieldName)}",
  "type": "text",
  "name": "${Variables.Competitor.fieldName}"
}
```

Here’s another that adds only month of the year values to the story:

```nolang
{
  "condition": "${!empty(Variables.Dataset_Dates[0].dateAlias)}",
  "action": "set",
  "description": "put selected fields in ED Story json",
  "path": "$.setup.fields",
  "value": "${array:union(Rules.CurrentNode, array:forEach(Variables.Dataset_Dates,'{\"type\":\"date\", \"name\": \"${var.dateAlias}\", \"periodicIntervals\": [\"MONTH_OF_YEAR\"], \"interval\": \"NONE\"}'))}"
}
```
