Explore Template Structure

Learning Objectives

After completing this unit, you’ll be able to:
  • Describe the various parts of Analytics Templates.
  • List the files that make up an Analytics Template.
  • Describe what each Analytics Templates file controls.

The CEO Raises the Bar

After completing the last unit, you’re jazzed to show the CEO how the new template works. (OK, you didn’t really do much since we made the template, but for now, let’s pretend you did.) So you take the CEO through the app creation process and show her the dashboards in the app, the Sales Performance and Pipeline Performance executive overviews.

The CEO is suitably appreciative, but she wants more. (Of course she does!) “Since we talked last, I found out some of our partners use Service Cloud and want that Service Performance dashboard, too. I want to make it real easy—we don’t want to give anyone a single reason not to love us. Can we give them the option of adding that dashboard?

“Also, turns out some of our partners are picky, picky, picky. I was using the dashboards during our weekly call, and a few folks hoped they could look at different data. A couple of them asked about different ways of showing where their accounts are located. And someone else mentioned they don’t track new business the way we do.”

Just to be sure you know what she’s talking about, you open the app and ask her to show you.

Execs Overview dashboard details

She says, “See Billing Country? Some of our smaller partners want to view that by state or city. And see Lead Source? That shows how we get new business, but lots of our partners don’t use the same terminology. Can you change that?”

Fortunately, you’ve reviewed the Analytics Templates Developer Guide and you already know the solution: Edit the template to add a configuration wizard with questions that let users customize their versions of the app. Remember, Execs Only 1 is a plain vanilla version of the exec app, with no variations possible.

Before you can edit the template, you need to understand what’s in it. In this unit, we run through the template files to show you how they control the template and, ultimately, the app you create from it.

Template JSON Files

When you create a template from an Analytics app, you get a directory of files that looks like this:Analytics Template file directory

It includes the JSON files that make up the template object. They define dashboards, datasets (external_files), and the dataflow. It also includes the files you edit to add the wizard and other functionality. Note that these files are only available when you retrieve the metadata after creating the template. To learn more about that, follow the link to Retrieve (Export) the WaveTemplate Object from the Analytics Templates Developer Guide in the Resources section at then end of this unit.

  • template-info.json manages all elements of your template, including metadata information about the template, the Analytics objects that define dashboards and lenses, and the other files that are part of the template.
  • ui.json manages the configuration wizard that drives app creation. It defines the number of wizard pages, the order of wizard questions, and any messages you want the user to see.
  • variables.json contains all template variables, including text for wizard questions and specifications for the answers. Variables also define conditional questions. For example, you may want some questions to appear in the wizard only if an org contains certain data. Or you might want to add more specific questions based on the answers to more general wizard questions.
  • template-to-app-rules.json defines the rules the template follows. For example, you could define a rule that specifies that if an org doesn’t use certain Salesforce objects, the app won’t refer to them in dashboards or include them in the dataflow. Rules also define how variables are handled. For example, if the wizard asks which fields to include in filters for accounts, template-to-app-rules.json determines how that choice is reflected in dashboards.
    Note

    Note

    We abbreviate the name of this file to rules.json in the rest of this module for ease of reading.

  • folder.json organizes the parts of dashboards, for example letting you set the order of dashboard in an app instead of keeping them in alphabetical order.

If you have sharp eyes, you might have noticed a JSON file for our missing Service Performance dashboard (Exec_Overview_Service_Performance.json). We’ll come back to that a little later.

Meet The Boss: Template-info.JSON

Let’s look at those files from Execs Only Template 1, starting with Template-info.JSON.

{
  "assetVersion" : 41,
  "name" : "Trailhead_Template_PartOne",
  "releaseInfo" : {
    "templateVersion" : "4.0"
  },
  //1-THE DASHBOARDS
  "dashboards" : [ {
    "file" : "dashboard/Exec_Overview_Pipeline_Performance.json",
    "name" : "Exec_Overview_Pipeline_Performance_PartOne",
    "label" : "Exec Overview - Pipeline Performance"
  }, {
    "file" : "dashboard/Exec_Overview_Sales_Performance.json",
    "name" : "Exec_Overview_Sales_Performance_PartOne",
    "label" : "Exec Overview - Sales Performance"
  } ],
  //2-TEMPLATE DESCRIPTION
  "description" : "Unlock the power of Einstein Analytics Templates.",
  "eltDataflows" : [ {
    "file" : "workflow/SalesAnalyticsDataflow.json"
  } ],
  //3-THE DATASETS
  "datasetFiles" : [ {
    "label" : "Users",
    "name" : "user_PartOne"
  }, {
    "label" : "Opportunities",
    "name" : "opportunity_PartOne",
    "userXmd" : "external_files/opportunity_XMD_template.json"
  }, {
    "label" : "User Allocation",
    "name" : "quota_PartOne",
    "userXmd" : "external_files/quota_XMD_template.json"
  }, {
    "label" : "Pipeline Trending",
    "name" : "pipeline_trending_PartOne",
    "userXmd" : "external_files/pipeline_trending_XMD_template.json"
  } ],
  "externalFiles" : [ {
    "file" : "external_files/plain_quota.csv",
    "name" : "plain_quota_PartOne",
    "schema" : "external_files/plain_quota.json",
    "type" : "CSV"
  } ],
  //4-THE TEMPLATE NAME
  "label" : "Execs Only Template 1",
  //5-REFERENCES TO OTHER FILES
  "folderDefinition" : "folder.json",
  "rules" : [ {
    "type" : "templateToApp",
    "file" : "template-to-app-rules.json"
  } ],
  "uiDefinition" : "ui.json",
  "variableDefinition" : "variables.json",
  "icons" : {
    "appBadge" : {
      "name" : "16.png"
    },
    "templateBadge" : {
      "name" : "trailhead_icon_160x160"
    },
    "templateDetail" : {
      "name" : "trailhead_detail"
    }
  }  
}
A good way to think about template-info.JSON is that it’s in charge of the template. It includes all the information required to create the app. You can see the metadata for the template and version information (the first few lines), dashboards (1 in the comments), a description of the template (2), datasets (3), and the template name (4). If you look closely at the bottom of the file, you see references to the other 3 JSON files (5).
Important

Important

The code samples in this module represent the major steps need to upgrade Execs Only Template 1 (EATP1) to Execs Only Template 2 (EATP2). We recommend removing the comments before trying to work with them yourself, since JSON does not support comments. You can download complete, functioning, uncommented template files from the link in the Resources section at the end of this unit.

Variables, UI, and Rules

Let’s take a close look at the other template object files, starting with variables.json.

{
  //1-THE DEFAULT VARIABLE
  "variableType": {
    "type": "ObjectType",
    "properties": {
      "createAllDashboards": {
        "type": "BooleanType"
       }
     },
  //2-THE OVERRIDE
  "Overrides": {
    "required": true,
    "description": "Internal configuration to allow asset creation overrides, not to be displayed in UI.",
    "defaultValue": {
      "createAllDashboards": false
    },
      "strictValidation": true
    }
  }
}

The file contains a single default variable (1) for creating all assets, that is createAllDashboards.

It also includes an override (2), which is set to false. This means that if we want the template to create any dashboards other than the ones referred to in template_info.json—namely our missing Service Performance dashboard—we have to explicitly say so. Keep that in mind for now—we show what to do about that soon.

Next, let’s examine ui.json. The file determines the contents of the configuration wizard. Execs Only 1 doesn’t have a wizard, so there’s nothing in the file—its default condition.

{
  "pages": [

  ]
}

Finally, here’s the Execs Only 1 rules.json file, also empty by default. Since users can’t make any choices from wizard questions, there are no rules for how to change dashboards. Notice that there are two sections: constants and rules. We’ll say more about those later.

{
  "constants": [],
  "rules": []
}

To give the CEO—and our partners—what they want, we’re going to edit all 4 files. We show you how that’s done in the next two units. But first, a few more questions to help you earn your badge for this module.

Resources

retargeting