Scripting
Model

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() to query records in a table and view.selectRecordsAsync() to query records in a view.

Example
// 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")}
`);
}
Example
// 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

typedef
Array<string>

The record IDs in this RecordQueryResult.

records

typedef
Array<Record>

The records in this RecordQueryResult. These are instances of the Record class.

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

getRecord

function
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 nameDescription
recordIdThe ID of the record you want to retrieve.
Example
let table = base.getTable("Tasks");
let queryResult = await table.selectRecordsAsync({fields: ["Description"]});
let record = queryResult.getRecord(queryResult.recordIds[0]);
console.log(record.getCellValue("Description"));