Communicate with Wave Dashboards Using the Web SDK

Easily interact with Wave in custom applications. Use Lightning Components for Visualforce, or your preferred development environment.

Would you like your application to communicate with your Wave dashboards, whether your application is built with the Lightning SDK, Visualforce, or mobile? How about from an application outside of Salesforce? Wouldn’t it be great if your application could apply filters or know about dashboard selections and filters made by a user?

Your application could take actions specific for your business if values fall outside of defined ranges. Or you could have an application that is a viewpoint for dashboards made available by different parts of your business application ecosystem. Imagine that: a single information source to present to your executive staff!

Salesforce introduces the Wave Analytics Web SDK. The events we’re making available in this release are the foundation for a new way of thinking about Wave applications. Coupled with the LockerService, you can even code your application outside of Salesforce—you can interact with Wave from any JavaScript application.

SDK Events

wave:update

Use this event to dynamically set the filter on a Wave dashboard or interact with the dashboard by dynamically changing the selection. It has three attributes: the unique ID of the Wave asset on which to apply the filter, the payload, and the asset type (currently only dashboard). The payload is a JSON string that identifies the datasets and any dimensions and field values.

wave:selectionChanged

This event is fired by a Wave dashboard for consumption by custom Lightning components. It provides the following attributes: the ID of the dashboard that fired the event and the payload. The payload object contains the selection information—the name of the step involved when changing the selection and an array of objects representing the current selection. Each object in the array contains one or more attributes based on the selection.

Note

Note

To use these events, you need the Wave platform license Insights Builder PSL.

Setting a Filter

This is a Lightning component example, where a component has already been defined, handlers have been set, and the update event has been registered in the custom component markup. But the controller is where the exciting stuff happens. The code shows how to construct the payload for the update event—in this case, setting StageName to Close Won in the oppty_test dashboard.

({
    doInit: function(component, event, helper) {
      component.set('v.filter', '{"oppty_test": {"StageName": ["Closed Won"]}}');
    },

    handleSendFilter: function(component, event, helper) {
      var filter = component.get('v.filter');
      var dashboardId = component.get('v.dashboardId');
      var evt = $A.get('e.wave:update);
        evt.setParams({
          id: dashboardId,
          value: filter,
          type: "dashboard"
        }); evt.fire();
      }
})

Reacting to a Selection

Here’s another Lightning component example. The component has already been defined and everything is registered, so this code shows the fun stuff in the controller—how to receive and iterate through the payload. The payload is an array of objects representing the current selection.

({
  handleselectionChanged: function(component, event, helper) {
    var params = event.getParams();
    var payload = params.payload;
    if (payload) {
      var step = payload.step;
      var data = payload.data;
      data.forEach(function(obj) {
        for (var k in obj) {
          if (k === 'Id') {
            component.set("v.recordId", obj[k]);
          }
        }
      });
    }
  }
})

Payload data can contain other objects, each in turn containing key-value pairs. For example, aside from the Id, you can also get the noun (for example, "dashboard") and the verb (for example, "selection").

Resources

This is just a taste. For more information about the new Web SDK events, see the Lightning Components Developer Guide and the Wave SDK Developer Guide.