Re: Sort a table within a script

1121 1
Showing results for 
Search instead for 
Did you mean: 
4 - Data Explorer
4 - Data Explorer

Hi there, I’m a newbie on airtable… and in the first script I write I encountered a problem and maybe somebody here can help me

let table = base.getTable(“MAIN_TABLE”);
let query = await table.selectRecordsAsync(
sort: [{ field: “STRING_FIELD”, direction: ‘desc’ },
{ field: “DATE_FIELD”, direction: ‘desc’ }

for (let registro of query.records) {

// Do some processing…


The problem that I have is that the order of the records is always the same, no matter what i write on the sort options invoking the table.selectRecordsAsync function…

There is something that I’m missing here? Anyone has encountered the same problem??

Thanks in advance

2 Replies 2

Hi @Mario_Cespedes - this is a hard one to spot, but an easy one to fix :slightly_smiling_face:

The keyword is sorts (plural) not sort, so something like this:

    sorts: [
        {field: "Age", direction: "asc"}


Thank you @JonathanBowen… really simple