# Using Apps With Data Service

> :::note
* A maximum of 1000 records for any filter are retrieved in runtime.
* After the data is loaded, the entities data is refreshed only when a rule is executed. Any updates made on Data Service via processes or other means are not picked up automatically. Make sure that you refresh the data explicitly in these scenarios.
* The `in` operator only supports primitive data types, such as `string`, `number`, `boolean`, `null`. The `in` operator is not supported in Data Service scenarios using `choice-set`. You can use the `contains` operator instead, but only for one input.
:::

## Background Information

:::note
* A maximum of 1000 records for any filter are retrieved in runtime.
* After the data is loaded, the entities data is refreshed only when a rule is executed. Any updates made on Data Service via processes or other means are not picked up automatically. Make sure that you refresh the data explicitly in these scenarios.
* The `in` operator only supports primitive data types, such as `string`, `number`, `boolean`, `null`. The `in` operator is not supported in Data Service scenarios using `choice-set`. You can use the `contains` operator instead, but only for one input.
:::

## Overview

Before starting this example, make sure that you have the proper permissions from Data Service. For more information, check the [Data Service - Managing Access](https://docs.uipath.com/data-service/automation-suite/2022.10/user-guide/managing-access) page.

For the purpose of this example we will use an entity called **Customer** with the following fields:

* Address
* Address 2
* City
* Email
* Name
* Phone
* Plan
* State
* Postal Code

## Filter Customer by State

:::note
Depending on your project's needs, you can choose to exclude certain conditions when using the **Filter** function. To exclude a condition, you can write an expression that resolves the filter field (first parameter of the condition array) to a `null`. For example, you can use the following:

`Filter(Customer, [If(IsBlank(Dropdown.Value), null, City), "=", Dropdown.Value])`

In this case, the filter on **City** is only applied when the **Dropdown** contains a value other than blank.
:::

Use the **Filter** function to retrieve multiple entity records applicable to the given condition. To select a single record, use the **Lookup** function instead.

1. Open your already existing application or start a new one.
2. Create a new table.
3. Add an entity to your app by clicking the **Add any** ![docs image](https://dev-assets.cms.uipath.com/assets/images/apps/apps-Add_Any_icon.png-6b01664f.webp) icon from the top of the canvas and selecting **Entity**.

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/apps/apps-91796-60fe10dd.webp)
4. Bind the newly-added entity to the table by adding it in the **Data Source** field of the table.
5. Filter the information from the table by state. For this example, to filter the customer by the state of California, add the following expression in the **Data Source** property of the table: `= Filter(Customer, [State, "=", "CA"])`.

## Sort Customers

1. Open your already existing application or start a new one.
2. Create a new table.
3. Add an entity to your app by clicking the **Add any** ![docs image](https://dev-assets.cms.uipath.com/assets/images/apps/apps-Add_Any_icon.png-6b01664f.webp) icon from the top of the canvas and selecting **Entity**.

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/apps/apps-91324-60fe10dd.webp)
4. Bind the newly-added entity to the table by adding it in the **Data Source** field of the table.

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/apps/apps-92336-aff1fe2d.webp)
5. Sort information from the table by by name in an descending order. For this example, add the following expression in the **Data Source** property of the table: `= Sort(Customer, Name, "Desc")`.

## Edit a Table

In this example we will build a data table with three buttons:

* Create New
* Edit Selected
* Delete Selected

The **Create New** and **Edit Selected** buttons will lead to the same page.

1. Open your already existing application or start a new one.

2. Create a new table.

3. Create two new buttons at the top of the table: **Edit Selected** and **Create New**. Create a third button at the bottom of the table called **Delete Selected**.

![docs image](https://dev-assets.cms.uipath.com/assets/images/apps/apps-92032-1a052016.webp)

4. Add an entity to your app by clicking the **Add any**![docs image](https://dev-assets.cms.uipath.com/assets/images/apps/apps-Add_Any_icon.png-6b01664f.webp) icon from the top of the canvas and selecting **Entity**.

![docs image](https://dev-assets.cms.uipath.com/assets/images/apps/apps-93004-60fe10dd.webp)

5. Bind the newly-added entity to the table by adding it in the **Data Source** field of the table.

![docs image](https://dev-assets.cms.uipath.com/assets/images/apps/apps-92504-aff1fe2d.webp)

6. Create a new page called **Edit/Create Customer** and add the following controls:

6.1 Add corresponding text fields for each of the entity fields and bind them.

6.2 Add a button under the text fields and name it **Save**.

![docs image](https://dev-assets.cms.uipath.com/assets/images/apps/apps-94928-169ef5c4.webp)

6.3 Set up a variable named `selectedCustomerId` by using a **Set Value** rule in the **value change** event of the table. Bind the variable to `Table.SelectedValue.Id` to use it on another page.

![docs image](https://dev-assets.cms.uipath.com/assets/images/apps/apps-98600-de1b1080.webp)

6.4 Add an **If-Then-Else** rule to the **Save** button and configure it:

* Add the following expression in the **If** field: `=selectedCustomerId` = `=""`, as in the figure below.

  ![docs image](https://dev-assets.cms.uipath.com/assets/images/apps/apps-96384-475a4cce.webp)

* Add a **Create/Update Entity Record** rule in the **Then** field and configure it as in the figure below:

  ![docs image](https://dev-assets.cms.uipath.com/assets/images/apps/apps-96357-64862ae2.webp)

* Add a **Create/Update Entity Record** rule in the **Else** field and add the following expression in the **Which entity record should be created/updated?** field: `=Lookup(Customer, [Id, "=", selectedCustomerId])`, where `Id` is the id of the entity. Configure the rule as in the figure below.

  ![docs image](https://dev-assets.cms.uipath.com/assets/images/apps/apps-96361-fd7d6666.webp)

7. Add a **Delete Entity Record** rule to the **Delete Selected** button from step **3** and add the following expression in the **Which entity record should be deleted?** field: Lookup(Customer, [Id, "=', Table.Id]).

8. Configure both **Edit Selected** and **Create New** buttons from step **3** to lead to the **Edit/Create Customer** page.
