
## RecordQueryResult

A RecordQueryResult represents a set of records. It's a little bit like a one-off Airtable view:
it contains a bunch of records, those records can be sorted according to your specification,
and just like a view, you can either have all the fields in a table available, or you can just
ask for the fields that are relevant to you.

You can use [table.selectRecordsAsync()](/developers/scripting/api/table.md#select-records-async) to query records in
a [table](/developers/scripting/api/table.md) and [view.selectRecordsAsync()](/developers/scripting/api/view.md#select-records-async)
to query records in a [view](/developers/scripting/api/view.md).

```js
// query for all the records in a table
let table = base.getTable("Tasks");
let queryResult = await table.selectRecordsAsync({
    fields: ["Description", "Priority"],
    sorts: [
       // sort by "Description" in ascending order
       {field: "Description"},
       // then by "Priority" in descending order.
       {field: "Priority", direction: "desc"},
    ]
});

// print ID & "Description" from each record:
for (let record of queryResult.records) {
    console.log(`
**${record.id}**
${record.getCellValueAsString("Description")}
`);
}
```

```js
// query for all the records in a view
let table = base.getTable("Tasks");
let view = table.getView("Todo");
let queryResult = await view.selectRecordsAsync({fields: ["Description"]});

// print ID & "Description" from each record:
for (let record of queryResult.records) {
    console.log(`
**${record.id}**
${record.getCellValueAsString("Description")}
`);
}
```

### recordIds

```js
Array<string>
```

The record IDs in this RecordQueryResult.

### records

> See also: [Record](/developers/scripting/api/record.md)
```js
Array<Record>
```

The records in this RecordQueryResult. These are instances of the [Record](/developers/scripting/api/record.md) class.

```js
let table = base.getTable("Tasks");
let queryResult = await table.selectRecordsAsync({fields: ["Description"]});
let record = queryResult.records[0];
console.log(record.getCellValue("Description"));
```

### getRecord

> See also: [Record](/developers/scripting/api/record.md)
```js
function (recordId: string) => Record
```

Get a specific record in the query result, or throw if that record doesn't exist or was filtered
out.

| Parameter name | Description |
|---|---|
| `recordId` | The ID of the [record](/developers/scripting/api/record.md) you want to retrieve. |

```js
let table = base.getTable("Tasks");
let queryResult = await table.selectRecordsAsync({fields: ["Description"]});
let record = queryResult.getRecord(queryResult.recordIds[0]);
console.log(record.getCellValue("Description"));
```
