Sort a table within a script

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

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

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

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



Thank you @JonathanBowen… really simple

1 Like