

# Configuring or editing an entity in an App Studio app
<a name="data-entities-edit"></a>

Use the following topics to configure an entity in an App Studio application.

**Topics**
+ [Editing the entity name](data-entities-edit-name.md)
+ [Adding, editing, or deleting entity fields](data-entities-edit-fields.md)
+ [Creating, editing, or deleting data actions](data-entities-edit-data-actions.md)
+ [Adding or deleting sample data](data-entities-edit-sample-data.md)
+ [Add or edit connected data source and map fields](data-entities-edit-connection.md)

# Editing the entity name
<a name="data-entities-edit-name"></a>

1. If necessary, navigate to the entity you want to edit.

1. In the **Configuration** tab, in **Entity name**, update the entity name and choose outside of the text box to save your changes.

# Adding, editing, or deleting entity fields
<a name="data-entities-edit-fields"></a>

**Tip**  
You can press CTRL\$1Z to undo the most recent change to your entity.

1. If necessary, navigate to the entity you want to edit.

1. In the **Configuration** tab, in **Fields**, you view a table of your entity's fields. Entity fields have the following columns:
   + **Display name:** The display name is similar to a table header or form field and is viewable by application users. It can contain spaces and special characters but must be unique within an entity.
   + **System name:** The system name is a unique identifier used in code to reference a field. When mapping to a column in an Amazon Redshift table, it must match the Amazon Redshift table column name.
   + **Data type:** The type of data that will be stored within this field, such as `Integer`, `Boolean`, or `String`.

1. To add fields:

   1. To use AI to generate fields based on entity name and connected data source, choose **Generate more fields**.

   1. To add a single field, choose **\$1 Add field**.

1. To edit a field:

   1. To edit the display name, enter the desired value in the **Display name** text box. If the system name of the field hasn't been edited, it will be updated to the new value of the display name.

   1. To edit the system name, enter the desired value in the **System name** text box.

   1. To edit the data type, choose the **Data type** dropdown menu and select the desired type from the list.

   1. To edit the field's properties, choose the gear icon of the field. The following list details the field properties:
      + **Required**: Enable this option if the field is required by your data source.
      + **Primary key**: Enable this option if the field is mapped to a primary key in your data source.
      + **Unique**: Enable this option if the value of this field must be unique.
      + **Use data source default**: Enable this option if the value of the field is provided by the data source, such as using auto-increment, or an event timestamp.
      + **Data type options**: Fields of certain data types can be configured with data type options such as minimum or maximum values.

1. To delete a field, choose the trash icon of the field you want to delete.

# Creating, editing, or deleting data actions
<a name="data-entities-edit-data-actions"></a>

Data actions are used in applications to run actions on an entity's data, such as fetching all records, or fetching a record by ID. Data actions can be used to locate and return data matching specified conditions to be viewed in components such as tables or detail views.

**Contents**
+ [Creating data actions](#data-entities-data-action-add)
+ [Editing or configuring data actions](#data-entities-data-action-edit)
+ [Data action condition operators and examples](#data-entities-data-action-operators)
  + [Condition operator support by database](#data-entities-data-action-operators-support)
  + [Data action condition examples](#data-entities-data-action-operators-examples)
+ [Deleting data actions](#data-entities-data-action-delete)

## Creating data actions
<a name="data-entities-data-action-add"></a>

**Tip**  
You can press CTRL\$1Z to undo the most recent change to your entity.

1. If necessary, navigate to the entity for which you want to create data actions.

1. Choose the **Data actions** tab.

1. There are two methods for creating data actions:
   + (Recommended) To use AI to generate data actions for you, based on your entity name, fields, and connected data source, choose **Generate data actions**. The following actions will be generated:

     1. `getAll`: Retrieves all the records from an entity. This action is useful when you need to display a list of records or perform operations on multiple records at once.

     1. `getByID`: Retrieves a single record from an entity based on its unique identifier (ID or primary key). This action is useful when you need to display or perform operations on a specific record.
   + To add a single data action, choose **\$1 Add data action**.

1. To view or configure the new data action, see the following section, [Editing or configuring data actions](#data-entities-data-action-edit).

## Editing or configuring data actions
<a name="data-entities-data-action-edit"></a>

1. If necessary, navigate to the entity for which you want to create data actions.

1. Choose the **Data actions** tab.

1. In **Fields** configure the fields to be returned by the query. By default, all of the configured fields in the entity are selected.

   You can also add **Joins** to the data action by performing the following steps:

   1. Choose ** \$1 Add Join** to open a dialog box.

   1. In **Related entity**, select the entity you want to join with the current entity.

   1. In **Alias**, optionally enter a temporary alias name for the related entity.

   1. In **Join type**, select the desired join type.

   1. Define the join clause by selecting the fields from each entity.

   1. Choose **Add** to create the join.

   Once created, the join will be displayed in the **Joins** section, making additional fields available in the **Fields to Return** dropdown. You can add multiple joins, including chained joins across entities. You can also filter and sort by fields from joined entities.

   To delete a join, choose the trash icon next to it. This will remove any fields from that join and break any dependent joins or constraints using those fields.

1. In **Conditions**, add, edit, or remove rules that filter the output of the query. You can organize rules into groups, and you can chain together multiple rules with `AND` or `OR` statements. For more information about the operators you can use, see [Data action condition operators and examples](#data-entities-data-action-operators).

1. In **Sorting**, configure how the query results are sorted by choosing an attribute and choosing ascending or descending order. You can remove the sorting configuration by choosing the trash icon next to the sorting rule.

1. In **Transform results**, you can enter custom JavaScript to modify or format results before they are displayed or sent to automations.

1. In **Output preview**, view a preview table of the query output based on the configured fields, filters, sorting, and JavaScript.

## Data action condition operators and examples
<a name="data-entities-data-action-operators"></a>

You can use condition operators to compare a configured expression value with an entity column to return a subset of database objects. The operators that you can use depend on on the data type of the column, and the type of database that the entity is connected to, such as Amazon Redshift, Amazon Aurora, or Amazon DynamoDB.

The following condition operators can be used with all database services:
+ `=` and `!=`: Available for all data types (excluding primary key columns).
+ `<=`, `>=`, `<`, and `>=`: Available only to numerical columns.
+ `IS NULL` and `IS NOT NULL`: Used to match columns that have null or empty values. Null values are often interpreted differently in each database, however in App Studio, the `NULL` operator matches and returns records that have null values in the connected database table.

The following condition operators can only be used in entities that are connected to database services that support them:
+ `LIKE` and `NOT LIKE`(Redshift, Aurora): Used for performing pattern-based queries in the connected database. The `LIKE` operator provides flexibility in search functionality because it finds and returns records that fit the specified patterns. You define the patterns using wildcard characters that match any character or sequence of characters within the pattern. Each database management system has a unique set of wildcard characters, but the two most popular are `%` to represent any number of characters (including 0), and `_` to represent a single character.
+ `Contains` and `Not Contains` (DynamoDB): Used for performing a case-sensitive search to determine whether the given text is found within the column values. 
+ `Starts With` and `Not Starts With` (DynamoDB): Used for performing a case-sensitive search to determine whether the given text is found at the beginning of the column values. 

### Condition operator support by database
<a name="data-entities-data-action-operators-support"></a>

The following table shows which data action condition operators are supported by each database that can connect to App Studio.


|  | =, \$1=, <, >, <=, >= | LIKE, NOT LIKE | Contains, Not Contains | Starts With, Not Starts With | IS NULL, IS NOT NULL | 
| --- | --- | --- | --- | --- | --- | 
|  **DynamoDB**  |  Yes  |  No  |  Yes  |  Yes  |  Yes  | 
|  **Aurora**  |  Yes  |  Yes  |  No  |  No  |  Yes  | 
|  **Redshift**  |  Yes  |  Yes  |  No  |  No  |  Yes  | 

### Data action condition examples
<a name="data-entities-data-action-operators-examples"></a>

Consider the following database table, which includes multiple items with `name`, `city`, and `hireDate` fields.


| name | city | hireDate | 
| --- | --- | --- | 
|  Adam  |  Seattle  |  2025-03-01  | 
|  Adrienne  |  Boston  |  2025-03-05  | 
|  Bob  |  Albuquerque  |  2025-03-06  | 
|  Carlos  |  Chicago  |  2025-03-10  | 
|  Caroline  |  NULL  |  2025-03-12  | 
|  Rita  |  Miami  |  2025-03-15  | 

Now, consider creating data actions in App Studio that return the `name` field for items that match specified conditions. The following list contains condition examples and the values that the table returns for each. 

**Note**  
The examples are formatted as SQL examples– they may not appear as they do in App Studio, but are used to illustrate the behavior of the operators.
+ `WHERE name LIKE 'Adam'`: Returns `Adam`.
+ `WHERE name LIKE 'A%'`: Returns `Adam` and `Adrienne`.
+ `WHERE name NOT LIKE 'B_B'`: Returns `Adam`, `Adrienne`, `Carlos`, `Caroline`, and `Rita`.
+ `WHERE contains(name, 'ita')`: Returns `Rita`.
+ `WHERE begins_with(name, 'Car')`: Returns `Carlos` and `Caroline`.
+ `WHERE city IS NULL`: Returns `Caroline`.
+ `WHERE hireDate < "2025-03-06"`: Returns `Adam` and `Adrienne`.
+ `WHERE hireDate >= DateTime.now().toISODate()`: Note that `DateTime.now().toISODate()` returns the current date. In a scenario where the current date is 2025-03-10, the expression returns `Carlos`, `Caroline`, and `Rita`.

**Tip**  
For more information about comparing dates and times in expressions, see [Date and time](expressions.md#expressions-date-time).

## Deleting data actions
<a name="data-entities-data-action-delete"></a>

Use the following procedure to delete data actions from an App Studio entity.

1. If necessary, navigate to the entity for which you want to delete data actions.

1. Choose the **Data actions** tab.

1. For each data action you want to delete, choose the dropdown menu next to **Edit** and choose **Delete**.

1. Choose **Confirm** in the dialog box.

# Adding or deleting sample data
<a name="data-entities-edit-sample-data"></a>

You can add sample data to entities in an App Studio application. Because application's don't communicate with external services until they are published, sample data can be used to test your application and entity in preview environments.

1. If necessary, navigate to the entity you want to edit.

1. Choose the **Sample data** tab.

1. To generate sample data, choose **Generate more sample data**.

1. To delete sample data, select the checkboxes of the data you want to delete, and press the Delete or Backspace key. Choose **Save** to save the changes.

# Add or edit connected data source and map fields
<a name="data-entities-edit-connection"></a>

**Tip**  
You can press CTRL\$1Z to undo the most recent change to your entity.

1. If necessary, navigate to the entity you want to edit.

1. Choose the **Connection** tab to view or manage the connection between the entity and a data source table where data is stored when your application is published. Once a data source table is connected, you can map the entity fields to the columns of the table.

1. In **Connector**, choose the connector that contains a connection to the desired data source table. For more information about connectors, see [Connect App Studio to other services with connectors](connectors.md).

1. In **Table**, choose the table you want to use as a data source for the entity.

1. The table shows the fields of entity, and the data source column they are mapped to. Choose **Auto map** to automatically map your entity fields with your data source columns. You can also map fields manually in the table by choosing the data source column in the dropdown for each entity field.