Skip to main content

Sort a table within a script

  • May 13, 2020
  • 2 replies
  • 69 views

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

This topic has been closed for replies.

2 replies

JonathanBowen
Forum|alt.badge.img+18

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"}
    ]

JB


  • Author
  • New Participant
  • May 13, 2020

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"}
    ]

JB


Thank you @JonathanBowen… really simple