Lightning Web Component getState Method

Use the getState method to retrieve the current state of the rendered Lightning web component for CRM Analytics dashboards.

Arguments 

Argument NameDescription
callbackThe callback function to handle the getState response. See the next section for a basic callback example.

Example 

Add your implementation of the getState call into the wrapper Javascript and HTML for your component.

To use the communityDashboard component, replace wave-wave-dashboard-lwc with wave-community-dashboard.

Note

The HTML for the component:

1<template>
2  <lightning-button variant="brand" label="Get Dashboard State" title="Get State Action" onclick={getState} class="slds-m-left_x-small"></lightning-button>
3  <wave-wave-dashboard-lwc dashboard="0FK5B000000XiK14AK" height="1000"></wave-wave-dashboard-lwc>
4</template>

The Javascript for the component, which implements getState():

1import { LightningElement } from 'lwc';
2
3export default class DashboardWrapper extends LightningElement {
4  getState () {
5    const dashboard = this.template.querySelector('wave-wave-dashboard-lwc');
6    dashboard.getState(function (result, error) {
7      if (error) {
8        console.warn("getState error: ", error);
9      }
10      if (result) {
11        let state = JSON.parse(JSON.stringify(result.payload));
12        console.warn("getState state: ", state);
13        let json = JSON.stringify(state, null, 2);
14        console.wave("getState as json: ", json);
15      }
16    });
17  }
18}

In this example, the callback function result contains a JSON payload with state attributes. Here’s a sample callback result.

1{
2  "state": {
3    "datasets": {},
4    "sObjects": {},
5    "steps": {
6      "Step_1": {
7        "values": [],
8        "metadata": {
9          "groups": ["Field1__c"]
10        }
11      }
12    }
13  }
14}

See Also