Select record(s) from table by ID(s)

Hey,

It takes a long long time to await table.selectRecordsAsync only to get a single record by id.

Is there a way to get a single record by ID from a table? Or multiple records by array of record IDs?

Use case is a very common one - once I get record ids from a linked record field I need to get the respective records from the linked table.

Thanks,
Ronen

1 Like

Nope, not yet. This is one of my biggest gripes with the Scripting API at the moment.

You cannot pick and choose which records you want with selectRecordsAsync. However, you can speed it it up by limiting the fields that are returned.

let query = await table.selectRecordsAsync( { fields: arrayOfFields } )

Here is a simplified version of how I usually get linked records.


let queryResults = await linkedTable.selectRecordsAsync({
  fields: arrayOfFields,
})

let linkedRecordValue = record.getCellValue(linkedRecordField)

let linkedRecords = linkedRecordValue.map(linkObj => 
  queryResults.getRecord(linkObj.id)
)

Hey @Taylor_Savage , any ETA on this? This really holds back script development productivity. I find myself spending a lot of time on creating complex selective views that should not take a lot of time to load but that still load way to many records when I need only one.

I am also adding many lookup fields to tables just to avoid needing to load a linked record.

One really great DX enhancing feature would be that whenever I do Record.getCellValue() of a linked record field, I can actually set an option to get an array of the linked records.

Thanks,
Ronen

Hey Ronen,

You can load a single record by ID by loading a query result for the table first:

let table = base.getTable('Table 1');
let query = await table.selectRecordsAsync();
let record = query.getRecord(recordId);
console.log(record.getCellValue('Name'));

Note that this still loads the entire table - it just lets you select a single record from it. So more of an ergonomic feature than a performance feature. Only actually selectively loading certain records for performance reasons is a tougher technical problem given how blocks currently work, but something we’re actively thinking about.