Top 4 quick JSON tricks for Wave

0
(0)

If you are new to Salesforce Wave or even if you have been using Wave for a while but never dared to look at what happens behind the dashboard, here are my top quick tricks to make some helpful changes in Wave.

Firstly, for every lens there is a underlying JSON code that defines the logic and visualisation. When you add that lens to a dashboard that JSON code is also copied over adding to the JSON code of your dashboard. Now this dashboard JSON has a certain structure, which looks something like this:

The quick changes I most often do in the JSON, because it’s easier or maybe not even available in the UI (just yet, hopefully) is:

  1. Add a limitation to the results of a lens
  2. Change the field that is being used in a grouping or a measure
  3. Remove or add a (hidden) filter to your lens
  4. Change the dataset to be used for a lens.

Before we begin

Before getting into the lens or dashboard JSON code it’s important to know where to find it. Once you are previewing your lens or dashboard simply find the command + e (if you are a mac user) or control + e (if you are a pc user) on your keyboard. This will take you write to the JSON editor, where you can do your modifications. To get back to the preview either use the same keys again or click cancel to revert back or done to preview your changes.

Sometimes when I do many changes I will copy the JSON into a text editor like Bracket or Notepad++. You can also use an online tool like JSON Editor Online.

Especially when viewing a dashboard JSON it is important to know what to look for. You will most likely do most of your changes to the “Step” section of the JSON. This is where the logic behind your graphs lie, hence grouping, measures, filters etc. As a dashboard consist of multiple steps the best way to find the one you are looking for is to go into your dashboard editor, click on your graph and then view the step section. Here you can find the step label that is referenced in the JSON code.

1. Add a limitation to the results of a lens

If the grouping you choose in a lens comes back with a lot of values then a graph can quickly become confusing and hard to read in a dashboard. The best way for you to control this is by setting up a limit on your step. In my example I have too many accounts to be able to see the details, so I want to limit the number of accounts I am being shown.

Find your step in the dashboard JSON.

TIP! Press command/control + F to open the JSON search bar and enter your step label.

The step should look something like this:

"StepAccountsSumAmoun_1": {
 "type": "aggregateflex",
 "visualizationParameters": {
 "visualizationType": "vbar",
 "options": {}
 },
 "query": {
 "groups": [
 "AccountId.Name"
 ],
 "measures": [
 [
 "sum",
 "Amount"
 ]
 ],
 "order": [
 [
 -1,
 {
 "ascending": false
 }
 ]
 ]
 },
 "isFacet": true,
 "useGlobal": true,
 "isGlobal": false,
 "label": "StepAccountsSumAmount",
 "datasets": [
 {
 "name": "Opportunity_with_Account_and_Campaign",
 "url": "/services/data/v39.0/wave/datasets/0Fb58000000CeCnCAK",
 "id": "0Fb58000000CeCnCAK"
 }
 ],
 "selectMode": "single"
 }

In order to limit the result we are going to adjust the JSON and add the “limit”, it should look like this:

"StepAccountsSumAmoun_1": {
 "type": "aggregateflex",
 "visualizationParameters": {
 "visualizationType": "vbar",
 "options": {}
 },
 "query": {
 "groups": [
 "AccountId.Name"
 ],
 "measures": [
 [
 "sum",
 "Amount"
 ]
 ],
 "limit": 20,
 "order": [
 [
 -1,
 {
 "ascending": false
 }
 ]
 ]
 },
 "isFacet": true,
 "useGlobal": true,
 "isGlobal": false,
 "label": "StepAccountsSumAmount",
 "datasets": [
 {
 "name": "Opportunity_with_Account_and_Campaign",
 "url": "/services/data/v39.0/wave/datasets/0Fb58000000CeCnCAK",
 "id": "0Fb58000000CeCnCAK"
 }
 ],
 "selectMode": "single"
 }

You can of course change the limitation to your need. But if you now preview the dashboard you can see the chart is more readable. If you get an error it most likely have something to do with a missing comma or quotes.

2. Change the field that is being used in a grouping or a measure

Using the same step, lets say I want to change the measure. Instead of showing “Sum of Amount” I want to show “Sum of Expected Amount”. Find your step again and where it says “measures”. Replace “Amount” with “ExpectedRevenue”, which is the name of the field in the dataset. It should look like this:

"StepAccountsSumAmoun_1": {
 "type": "aggregateflex",
 "visualizationParameters": {
 "visualizationType": "vbar",
 "options": {}
 },
 "query": {
 "groups": [
 "AccountId.Name"
 ],
 "measures": [
 [
 "sum",
 "ExpectedRevenue"
 ]
 ],
 "limit": 20,
 "order": [
 [
 -1,
 {
 "ascending": false
 }
 ]
 ]
 },
 "isFacet": true,
 "useGlobal": true,
 "isGlobal": false,
 "label": "StepAccountsSumAmount",
 "datasets": [
 {
 "name": "Opportunity_with_Account_and_Campaign",
 "url": "/services/data/v39.0/wave/datasets/0Fb58000000CeCnCAK",
 "id": "0Fb58000000CeCnCAK"
 }
 ],
 "selectMode": "single"
 }

Preview your dashboard and notice the sum has now changed.

You can in the same way change the grouping to another field in the dataset.

3. Remove or add a (hidden) filter to your lens

Sometimes when you are creating lenses you may add filters to them to narrow your results. Once you clip them to the dashboard it will copy that filter. But that also means that if there are conflicting filters because of any list filters you might have created, you would have to remove those “hidden” filters on your step. Instead of creating the step all over you can simply modify the JSON.

First find your step in the JSON. You might use same approach as you did adding the limit to your step. In my example there is a filter defining the timeframe. However, looking at the dashboard that is not clear for the end-user. So I would like to remove that filter and add a date widget to the dashboard instead. That way the end-user has complete control of the timeframe of the data.

In order to remove the filter I find the “query” section of my step and where is says “filters”.

"StepIndustryAmount_1": {
 "type": "aggregateflex",
 "visualizationParameters": {
 "visualizationType": "vbar",
 "options": {}
 },
 "query": {
 "filters": [
 [
 "Close Date",
 [
 [
 1411171200000,
 1510389717000
 ]
 ],
 ">=<="
 ]
 ],
 "groups": [
 "AccountId.Industry"
 ],
 "measures": [
 [
 "sum",
 "Amount"
 ]
 ],
 "order": [
 [
 -1,
 {
 "ascending": false
 }
 ]
 ]
 },
 "isFacet": true,
 "useGlobal": true,
 "isGlobal": false,
 "label": "StepIndustryAmount",
 "datasets": [
 {
 "name": "Opportunity_with_Account_and_Campaign",
 "url": "/services/data/v39.0/wave/datasets/0Fb58000000CeCnCAK",
 "id": "0Fb58000000CeCnCAK"
 }
 ],
 "selectMode": "single"
 },

In the step remove the highlighted section above. It should now look like this:

"StepIndustryAmount_1": {
 "type": "aggregateflex",
 "visualizationParameters": {
 "visualizationType": "vbar",
 "options": {}
 },
 "query": {
 "groups": [
 "AccountId.Industry"
 ],
 "measures": [
 [
 "sum",
 "Amount"
 ]
 ],
 "order": [
 [
 -1,
 {
 "ascending": false
 }
 ]
 ]
 },
 "isFacet": true,
 "useGlobal": true,
 "isGlobal": false,
 "label": "StepIndustryAmount",
 "datasets": [
 {
 "name": "Opportunity_with_Account_and_Campaign",
 "url": "/services/data/v39.0/wave/datasets/0Fb58000000CeCnCAK",
 "id": "0Fb58000000CeCnCAK"
 }
 ],
 "selectMode": "single"
 },

That’s it! You can now add a the date step to your dashboard.

4. Change the dataset to be used for a lens

I sometimes find that I design a dashboard and in the process realise that I can’t use that dataset because it has the wrong root object. Or maybe a new version of the dataset has been released. It can be really annoying because that means that your new dashboard don’t show the right data. Instead of creating your dashboard from scratch you can in the dashboard JSON change the reference.

The first you want to do is retrieve the id and name of the dataset. The easiest way to make sure you have all the details is to create a new lens from the dataset and clip it into a blank dashboard. Once you have that you can easily find the dataset name and id. Open your new dashboard JSON and scroll all the way to the bottom where you find the section “datasets”.

"datasets": [
 {
 "id": "0Fb58000000CeCnCAK",
 "name": "Opportunity_with_Account_and_Campaign",
 "url": "/services/data/v39.0/wave/datasets/0Fb58000000CeCnCAK"
 }
 ]

Now open up your existing dashboard JSON and find the same section.

 "datasets": [
 {
 "id": "0Fb58000000CeWDCA0",
 "name": "Opportunity_with_Account",
 "url": "/services/data/v39.0/wave/datasets/0Fb58000000CeWDCA0"
 }
 ]

Now you want to search and replace for the “name” attribute as well as the id.

TIP! Press command/control + F to open the JSON search bar, press it again to open the JSON replace bar.

In the search bar put in “name”: “Opportunity_with_Account” and in the replace bar put in “name”: “Opportunity_with_Account_and_Campaign” and click on all.

Next do the same for the id.

That’s it! Now you have changed the reference from one dataset to another without recreating the whole dashboard.

How useful was this post?

Click on a star to rate useful the post is!

Written by


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.