# Enhancing AARI Table Fields

## Table Operations

### Reading All Rows in a Table

{% hint style="info" %}
The “Read AARI Table Field” brick is deprecated and does not work on recent Control Room versions. Instead, use the "Read AA Co-Pilot Table Field" brick&#x20;
{% endhint %}

1. Add the “Read AA Co-Pilot Table Field” brick
2. Enter a selector for the field name of the table, e.g., `#field-Table0`, `#field-Table1`, etc. When you type in the selector, PixieBrix will highlight the table:\
   ![](/files/VTHWQ3bEUAk7AdFRvtZq)
3. :warning: If you are using the brick in a Trigger, set the Root Mode of the brick to `Document`. If set to Inherit, PixieBrix will not find the table because it will search within the element that triggered the event<br>

   <figure><img src="/files/27i27lim91IAMhkc8iK1" alt=""><figcaption></figcaption></figure>

### Setting Cell Values in a Table

1. Add the “Set AARI Table Field Values” brick
2. :warning:If you are using the brick in a Trigger, set the Root Mode of the brick to `Document`. If set to Inherit, PixieBrix will not find the table because it will search within the element that triggered the event

### Handling Row Clicks

1. Add a Click handler targeting the table field, e.g., `#Table1 tbody tr`
2. Set the target mode to `root`. By setting the mode to `root` the trigger will pass along the row element, even if the use clicks on a cell or input within the row\
   ![](/files/sRTzekWZIZRiBWBw4Li1)
3. Add the “Read AARI Table Field Row” brick and rename the output key to `row`\
   ![](/files/UhwD1wmxa6ihIaSMQjqr)
4. Leave the `rowSelector` blank and set the Root Mode to `Inherit` for the brick to read from the row that was clicked\
   ![](/files/KnYNrdmAdt8fseojZo3t)
5. When you click the row, the output of the brick with be available as an array at `@row.values`

### Reading a Column by Name

1. Add the "Read AARI Table Field Column” brick
2. Provide the table selector based on the field name of the table, e.g., `#Table1`
3. Provide the column heading to read, e.g., `Column 1`
4. :warning:If you are using the brick in a Trigger, set the Root Mode of the brick to `Document`. If set to Inherit, PixieBrix will not find the table because it will search within the element that triggered the event

### Highlighting Cells

1. Add the “Highlight AARI Table Cells” brick
2. :warning:If you are using the brick in a Trigger, set the Root Mode of the brick to `Document`. If set to Inherit, PixieBrix will not find the table because it will search within the element that triggered the event

### Appending a Row to a Table

1. Add the “Append AARI table row” brick
2. Provide the table selector based on the field name of the table, e.g., `#Table1`
3. Provide an array of values to write in the new row. You can also pass an array of values<br>

   <figure><img src="/files/f0lXQi6Vp2hSILptjjSq" alt=""><figcaption></figcaption></figure>
4. :warning: If you are using the brick in a Trigger, set the Root Mode of the brick to `Document`. If set to Inherit, PixieBrix will not find the table because it will search within the element that triggered the event

## Table Validation and Calculations

### Example: Checking Aggregate Values

* Add the `@pixiebrix/jq` brick
* Pass the output key of the “Read AARI Table Field” brick for the data property
* The check if the value in the last row is equal to the sum of the proceeding columns, use the following jq filter:

  | Property | Value                                                                                           |
  | -------- | ----------------------------------------------------------------------------------------------- |
  | filter   | `(.rows[-1]["Column 1"] \| tonumber) == (.rows[0:-1] \| map(.["Column 1"] \| tonumber) \| add)` |
  | data     | `@table`                                                                                        |

The `(.rows[-1]["Column 1"] | tonumber)` expression gets the value in the last row and converts it to a number

The `(.rows[0:-1] | map(.["Column 1"] | tonumber) | add)` expression gets the proceeding rows, converts the value in Column 1 to a number, and sums the values

### Example: Multi-Column Validation

* Add the `@pixiebrix/jq` brick
* Pass the output key of the “Read AARI Table Field” brick for the data property
* To report rows where the value in “Column 1” is greater than the value in “Column 2”, use the following jq filter:

  | Property | Value                                                                                                                                         |
  | -------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
  | filter   | `.rows \| map((.["Column 1"] \| tonumber) > (.["Column 2"] \| tonumber)) \| to_entries \| map(select(.value)) \| map({row: .key, column: 1})` |
  | data     | `@table`                                                                                                                                      |

```
.row |

# Map to an array of true/false with the condition
map((.["Column 1"] | tonumber) > (.["Column 2"] | tonumber)) |

# Map to an array of records with {key: <row index>, value: <condition>}
to_entries |

# Exclude entries where the condition is false
map(select(.value)) | 

# Map to an array of rows/columns indexes (e.g., to pass to the Highlight AARI Table Cells brick)
map({row: .key, column: 1})
```

* Pass the output of the jq brick to the Highlight AARI Table Cells brick

## Writing Table Selectors

#### Table Selectors

The AARI Table Fields can each be targeted with a selector corresponding to the field in the form `#Table0`, `#Table1`

#### Column Selectors

To target a particular column in the table, you can:

* Target the column id: `#Table1 td:has(#Table1_col0-defaultValue)`. NOTE: the column id is not necessarily the column index. The column id is dependent on which order the the columns were added during AARI form creation
* Target the column by index (1-indexed): `#Table1 td.preview-table__body-column:nth-child(1)`

## Known Limitations

### “Attach Autocomplete” brick fills multiple cells when a value is selected

There is a known issue when selecting a value from Attach Autocomplete brick that it fills all the inputs matching the selector. (I.e., as opposed to only filling the input for which the autocomplete was shown)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.pixiebrix.com/integrations/automation-anywhere/enhancing-aari-table-fields.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
