# update

## Description

Updates the data from a dataset.

## Input / Parameter

| Name    | Description                                                             | Input Type   | Default | Options | Required |
| ------- | ----------------------------------------------------------------------- | ------------ | ------- | ------- | -------- |
| dataset | The name of the dataset that is created in Services.                    | Text         | -       | -       | Yes      |
| filter  | The filters to be applied.                                              | FilterFormat | -       | -       | No       |
| data    | Multiple dynamic attributes with values associated with each attribute. | Object       | -       | -       | Yes      |
| extra   | The stored value that is passed to all the callbacks.                   | Any          | -       | -       | No       |

### FilterFormat (Object)

The format used for filtering in the parameter `filter`.

| Key      | Description                                    | Input Type | Default | Options | Required |
| -------- | ---------------------------------------------- | ---------- | ------- | ------- | -------- |
| operator | Query operators used to filter multiple times. | Text       | And     | Or, And | No       |
| data     | Set of rules for another group of queries.     | List       | -       | -       | No       |

#### data (List)

Will contain a list of one (1) or more objects with the following structure (dataset, operator, value) and contain zero (0) or more objects with the same structure (FilterFormat only). This can be another FilterFormat to create grouped queries.

| Key      | Description                                                    | Input Type | Default | Options                                                                                                                                                                     | Required |
| -------- | -------------------------------------------------------------- | ---------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| dataset  | The dataset to filter.                                         | Text       | -       | -                                                                                                                                                                           | No       |
| field    | The field to be filtered.                                      | Text       | -       | -                                                                                                                                                                           | Yes      |
| operator | Operators to be used for specific filtering.                   | Text       | -       | Equal, Not\_Equal, Is\_Null, Is\_Not\_Null, Greater\_Than, Greater\_Than\_Or\_Equal, Less\_Than, Less\_Than\_Or\_Equal, Like, Not\_Like, In, Not\_In, Between, Not\_Between | Yes      |
| value    | The value to perform the query, which depends on the operator. | Any        | -       | -                                                                                                                                                                           | No       |

## Output

| Description                        | Output Type |
| ---------------------------------- | ----------- |
| Returns the formatted information. | Object      |

### Object

| Key     | Description                                                             | Output Type |
| ------- | ----------------------------------------------------------------------- | ----------- |
| success | Boolean value to denote whether the function was executed successfully. | Text        |
| message | The message to print.                                                   | Text        |
| data    | Any additional message or data to print.                                | Text        |

## Callback

### callback

The action performed if this function runs successfully.

| Description                                        | Output Type |
| -------------------------------------------------- | ----------- |
| Returns the list of updated data from the dataset. | List        |

### errorCallback

The action performed if this function does not run successfully.

| Description               | Output Type |
| ------------------------- | ----------- |
| Returns an error message. | Text        |

## Example

In this example, we will update the local table data from the local storage.

```js
Note: This example will only work after the user has created the data using `Dataset.insert` function).
```

### Steps

1. Create a `Local Table` in the services panel in the service page if there is no table created yet. For the fields, add `name`and `title` as object key with Text type.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-b87cd62feb0cb7e6500969aefd8b62d33a145c59%2Fupdate-step-1.png?alt=media)
2. Drag a button component to a page in the mobile designer.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-56c9d5167b84a49ca70679c2c3824ac2e30aa199%2Fupdate-step-2.png?alt=media)
3. Select the event `press` and drag the `Dataset.update` function to the event flow and fill in the parameter. For the `filter` and `data` parameters, change it's type to a function / subflow.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-2992ef29e1c50fa55f2bee543a379781cba5fc3d%2Fupdate-step-3.png?alt=media)
4. For the `filter` parameter, change it's type to a function / subflow and drag `Conversion.toObject` to the subflow. Then add `data` as an object key and change it's type to a function / subflow.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-d1612060e7eedc90d9884e809714020fef22faf4%2Fupdate-step-4.png?alt=media)
5. Drag the function `Conversion.toObject` to the new subflow. Then add `field`, `operator` and `value` as object keys with `name`, `like`, `n%` as their values respectively.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-b105a9e4472e6a85140314c0ffa4549edd9baaee%2Fupdate-step-5.png?alt=media)
6. For the `data` parameter, it's type to a function / subflow and drag `Conversion.toObject` to the subflow. Then add `title` as an object key, with `new value` as it's value.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-5d0336734962a49bc0e0e95753d41ef20da9d032%2Fupdate-step-6.png?alt=media)

### Result

1. The data should be updated with the changes passed. The result can be printed in the console using the Dataset.read and Log.write functions.
2. Refer to the example in [Dataset.read](https://docs.emobiq.com/emobiq-client/006-actions-and-visual-logic/action-reference/react-native/dataset/read) for more information on viewing the data.
