Help

Upcoming database upgrades. Airtable functionality will be reduced for ~15 minutes at 06:00 UTC on Feb. 4 / 10:00 pm PT on Feb. 3. Learn more here

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

Topic Labels: Scripting extentions
5328 9
cancel
Showing results for 
Search instead for 
Did you mean: 

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

9 Replies 9

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.

Hello Support team.
Nice to meet you.
I want to get record id using airtable script when I click on checkbox in airtable.

Please see these screenshots.

For example, when I click on checkbox, then it will be triggered to the script, and then script will call a specific URL which I will be defined.
In airtable script, I want to get the record id of the checkbox I checked, so that I can get field values(eg: name, email, gender etc) based on the record id, and then I can pass them as parameter with a specific URL.
But I can find any solution regarding this problem.
I mean, there is no any solution or document of how to get record id.
I hope you understand what I explained.
Please let me know your opinion.
I am waiting for your reply.
Thanks.

Hello Matt.
Nice to meet you.
I want to get record id using airtable script when I click on checkbox in airtable.

Please see these screenshots.

For example, when I click on checkbox, then it will be triggered to the script, and then script will call a specific URL which I will be defined.
In airtable script, I want to get the record id of the checkbox I checked, so that I can get field values(eg: name, email, gender etc) based on the record id, and then I can pass them as parameter with a specific URL.
But I can find any solution regarding this problem.
I mean, there is no any solution or document of how to get record id.
I hope you understand what I explained.
Please let me know your opinion.
I am waiting for your reply.
Thanks.

Hi Ronen.
I don’t understand. Please see my post and let me know your thoughts.
Thanks.

This is a community forum where most posters are simply other Airtable users. This is not a way to reach the support team.

That said, your automation script can get the record ID of the triggering script from an input variable.

Create the input variable in the left panel of the script editor and set it to the record ID of the triggering record. Then use input.config in your script to get the value. You can see the documentation for more info.

Hi Kuovonne.
Thanks for your reply.
But Your explanation is too general.
Yes, I can see input.config() and “Add input variable” button, but it doesn’t make sense.
Please guide me on how to use input.config and input variable.
Thanks.