# Update app data using accessors

### Example to use accessors

In the following example,  app data and accessors will be used to display and update data.

#### 1. Define app data

First, in the app data level, add a new data field named `test_number`, whose Data type is number, Storage type is "In Memory" and Default Data Value is 1.

![](https://3574406564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB_fx7PCUqvFEdrucJC%2Fuploads%2FFlQO4N2pJGMf5OHCwhAa%2Fimage.png?alt=media\&token=19645a30-f518-4661-ab02-ee8da8c37264)

#### 2. Place a text element and [#access-data-in-the-configuration-panel](#access-data-in-the-configuration-panel "mention")

Drag a text element to the canvas and enter `${#app.test_number}` in text field. In the app view, the text will display the value of `test_number`.

<figure><img src="https://3574406564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB_fx7PCUqvFEdrucJC%2Fuploads%2FNcSC4SW7ep7AlYrbW1Fk%2Fimage.png?alt=media&#x26;token=300d261d-c440-4485-b38a-94833918f93f" alt=""><figcaption></figcaption></figure>

#### 3. Place a button and add interaction

Drag a button onto the page below the text. Then, open the interaction panel to add an action: App -> Set app data after the event 'click button.' Next, click on the f(x) icon to edit the transformer.&#x20;

{% hint style="info" %}
Hint: the transformer uses JavaScript. \
For more information, refer to the related page: [interactions](https://docs.acho.io/app-builder/app-construction/interactions "mention").
{% endhint %}

#### 4. Use transformer to update data and  [#access-data-in-the-transformer](#access-data-in-the-transformer "mention")

Using accessor, edit transformer code, remember to click the update button to save the change. Code for reference:

```
function transformer(payload, context) {
  const test_number = context.getData("#app.test_number");
	const updated_test_number = (test_number + 1) % 3;
  const parameters = {"field":"test_number","value":updated_test_number};
  return parameters;
}
```

<figure><img src="https://3574406564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB_fx7PCUqvFEdrucJC%2Fuploads%2Fi9hbGrm8lJjg7m8mMd8t%2Fimage.png?alt=media&#x26;token=e3437b78-b458-407a-afd2-9d80c625a9b1" alt=""><figcaption></figcaption></figure>

#### 5. Click Preview to see the result

<figure><img src="https://3574406564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MB_fx7PCUqvFEdrucJC%2Fuploads%2F8RGPQa64kCzeEH6dgjee%2FData_store_example.gif?alt=media&#x26;token=0c1c99ad-3a48-4b9f-9074-f8ee64543e3c" alt=""><figcaption></figcaption></figure>
