CRM Analytics Aura Events - Discover Event

This event sends a request to CRM Analytics dashboards to identify their assets.

Example - Setting Up Your Request and Receiving a Response 

The wave:discover event sends a global request to listening CRM Analytics dashboard assets to respond with their identifying information (via the wave:discoverResponse event). You can include your own parameter in the response.

The wave:discover and wave:discoverResponse events work hand-in-hand. They’re particularly useful for discovering when a dashboard is being added dynamically to the page, or whether the page has multiple dashboards.

Using the Developer Console, create an Aura component and copy the following markup into the component. The markup sets up the handlers for the events, and adds buttons for adding a dashboard and for discovering dashboards.

1<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
2    <aura:handler event="wave:discoverResponse" action="{!c.handleDiscoverResponse}"/>
3    <aura:registerEvent name="discoverEvent" type="wave:discover"/>
4
5    <ui:inputText label="Dashboard Name" aura:id="idTextBox"/>
6    <ui:button label="Add Dashboard" press="{!c.addDashboard}"/>
7    <ui:button label="Are you there?" press="{!c.discoverDashboard}"/>
8    {!v.body}
9    <ui:outputText aura:id="outName" value="" class="text"/>
10</aura:component>

Add a controller to the bundle, then copy the following JavaScript into it. This code shows how to fire the discover event, and how to use the result when the discoverResponse event is fired. The code also shows how to create dashboard components.

1({
2    addDashboard: function(component, event, helper) {
3        var selectCmp = component.find("idTextBox");
4        var config = {
5            "developerName": selectCmp.get("v.value"),
6            "showHeader": false,
7            "height": 400
8        };
9        $A.createComponent("wave:waveDashboard", config,
10            function(dashboard, status, err) {
11                if (status === "SUCCESS") {
12                    dashboard.set("v.rendered", true);
13                    dashboard.set("v.showHeader", false);
14                    component.set("v.body", dashboard);
15                } else if (status === "INCOMPLETE") {
16                    console.log("No response from server or client is offline.")
17                } else if (status === "ERROR") {
18                    console.log("Error: " + err);
19                }
20            }
21        );
22    },
23    discoverDashboard: function(component, event, helper) {
24        $A.get("e.wave:discover").fire();
25    },
26    handleDiscoverResponse: function(cmp, event, helper) {
27        var myText = cmp.find("outName");
28        myText.set("v.value", event.getParam("developerName"));
29    },
30})

That’s it! You can use these events to get some context about available dashboard components, and then interact with them via the Update and selectionChanged events.

Resources 

For more information about Aura events and other Lightning development features, see the Lightning Aura Components Developer Guide.