---
schema_version: "1"
id: 8f320374358172871aed7bd494cc53b5ee6c0674e0c07d9e423da4948fe6f367
title: setState Method
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/analytics/dashboard-component/guides/bi-dbcomp-setstatemethod.md
canonical_url: https://developer.salesforce.com/docs/analytics/dashboard-component/guide/bi-dbcomp-setstatemethod.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: ed73049d53ae6c5d36ce8fceb71f09ca2b07cde32769e8d3aa002a9c1f9f82c6
products:
  - Analytics Dashboard Component
  - analytics
---
# setState Method

Use the `setState` method to dynamically set the state on an Aura component for CRM Analytics dashboards, or interact with the dashboard by dynamically changing the selection.

## Arguments

| Argument Name | Description                                                                                               |
| ------------- | --------------------------------------------------------------------------------------------------------- |
| `callback`    | The callback function to handle the `getState` payload response. See the next section for a basic `callback` example.                           |

For `setState`, the `config` parameters are:

- `state`
  - : Required; the dashboard state to use for update.
- `pageId`
  - : Required; the dashboard page ID to update.
- `replaceState`
  - : Optional; indicates whether to replace the dashboard state (`true`) or not (`false`). The default value is `false`.

**note:** When the `replaceState` parameter is `false` or not passed, only filters and step selections explicitly passed in the `state` parameter are updated. Any other state changes made since the dashboard was loaded are still present. When `replaceState` is `true`, the dashboard is reset with the provided external state, clearing any other selections made since the dashboard was loaded.

## Example

Add your implementation of the `setState` call into the controller.js for your Aura component. The `config` JSON is created with the required `pageId` and `state` attributes and the optional `replaceState` attribute.

```javascript
({
    setState : function(component, event, helper) {
        var dashboard = component.find('myDashboard');

        var config = {
            "pageId": "public_page",
            "replaceState": true,
            "state": {
                "datasets": {},
                "steps": {
                    "StepName" : {
                        "values": [],
                        "metadata": {"groups": ["GroupSource"]}
                    },
                    ...
                }
            }
        }

        dashboard.setState(config);
    }
})
```

The `state` can be set dynamically from user input or from another dashboard’s `state`. For the complete dashboard `state` structure, refer to the [Analytics Dashboard JSON Reference](https://developer.salesforce.com/docs/atlas.en-us.bi_dev_guide_json.meta/bi_dev_guide_json/bi_dbjson_intro.htm) guide.

**See Also**

- [`getState` Method](https://developer.salesforce.com/docs/analytics/dashboard-component/guide/bi-dbcomp-lwc-getstatemethod.md)
