Help

The Community will be temporarily unavailable starting on Friday February 28. We’ll be back as soon as we can! To learn more, check out our Announcements blog post.

Mimicking the deprecated selectRecordsAsync() behavior

Topic Labels: Scripting extentions
Solved
Jump to Solution
3972 2
cancel
Showing results for 
Search instead for 
Did you mean: 

You’ve probably all seen the following warning by now:
image

I’m guessing the deprecated behavior might still work well into 2022, but if you want to future-proof your scripts right now and/or depend on the old behavior, here’s the cleanest, functional way of mimicking it I’ve found so far:

const 
    table = base.getTable(yourTableName),
    fields = table.fields.map( f => f.name),
    query = await table.selectRecordsAsync({fields})

This particular destructuring syntax obviously depends on your scope being clean.

But in practice, I’d usually just write this:

const
    table = base.getTable(yourTableName),
    query = await table.selectRecordsAsync({
        fields:table.fields.map(f=>f.name)
    })

Either way, I figured I’ll share this and ask if anyone has figured out a quicker method.

1 Solution

Accepted Solutions
SergioCodes
8 - Airtable Astronomer
8 - Airtable Astronomer

Hi @Dominik_Bosnjak,

I use the “fields” array directly from the table; there´s no need to “map” the “fields” array.

const Table = base.getTable("TableName");
const query = await Table.selectRecordsAsync({ fields: Table.fields });

Best
Sergio
https://devblocks.agency
If this reply fixed your problem, please mark it as a solution :white_check_mark:

See Solution in Thread

2 Replies 2
SergioCodes
8 - Airtable Astronomer
8 - Airtable Astronomer

Hi @Dominik_Bosnjak,

I use the “fields” array directly from the table; there´s no need to “map” the “fields” array.

const Table = base.getTable("TableName");
const query = await Table.selectRecordsAsync({ fields: Table.fields });

Best
Sergio
https://devblocks.agency
If this reply fixed your problem, please mark it as a solution :white_check_mark:

Awesome, didn’t know you could just pass an entire field object like that, cheers.