Help

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

Topic Labels: Scripting extentions
12753 9
cancel
Showing results for 
Search instead for 
Did you mean: 
Ronen_Babayoff
7 - App Architect
7 - App Architect

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
Matt_Caruso
6 - Interface Innovator
6 - Interface Innovator

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)
)
Ronen_Babayoff
7 - App Architect
7 - App Architect

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

Taylor_Savage
7 - App Architect
7 - App Architect

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.

Shang
4 - Data Explorer
4 - Data Explorer

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.