How to get Latest record created in airtable?

Hi everyone,

I have a table with created date column and some data, as soon as new record is created I have created a automation script the extracts the newly created record by sorting this column in descending order and getting the getting the first record by using query.records[0](which is the last record created, because it is in descending order).

My question is, is there any way other than this to extract the latest record created?

I also have a column that is auto increment id, I was thinking of extracting the highest value from this column as the latest record, but could not find how to find max value of column by writing in automation script.

Thank you

1 Like

hi @Rohith_S,
from what you are mentioning, it seems that your automation’s trigger is the creation/update of a record inside the Airtable and in the script you want to refer to that specific record. I think the easiest way is to use the config parameters inside the script action to find the exact record id of the record that set the trigger. And then use the id in your script to find the specific record you are aiming to use. I think this is the most accurate approach as it allows you to pinpoint the exact record that triggered the automation.

P.S. you could also use the auto increment id in the same way that you are using the created date column. So, when running the selectRecordsAsync function to get the array with all the records which I believe you named query, you would add the sort parameter and sort by the auto increment id in descending order, then use query.records[0] to find the record with the higher auto increment id

Hope this helps!

Website: alessiomonino.com
Calendly: Calendly - Alessio Monino
Email: alessio.monino@gmail.com

Hi @Alessio_Monino, Thank you for replying

Yes. I want the automation to run as new record is created, but my question is how to get that triggered record details in script or how do you get the id of triggering record in script?
I don’t want to select all the records and then sort them and then get the latest record, I just want to select the record that was created and use it in the script.
If this is not possible I was wondering if i can select the record with the maximum value of the auto increment id field which represents new record.

hi @Rohith_S,
exactly, you can use the config parameters to get the relevant record. You can access those parameters with input.config(). This link from the Airtable documentation is probably helpful: Airtable Scripting

Hope this helps!

Website: alessiomonino.com
Calendly: Calendly - Alessio Monino
Email: alessio.monino@gmail.com

1 Like

Looks like these threads are duplicates:

the no scripting solution as a work around is as follows

Let’s say your Table is called Records

create a separate table e.g. called “Last records”

This would have a linked record field called “Records” which was linked to your first table

Last records table would also consist of look up fields which looked up the values from the linked record.

It would have one record in it (create a formula to find the record id) named LASTRECORD

Then an automation would be created triggered on a new record in your records table which would update your LASTRECORD record in last records table (found by the record id) with the name of the new record in records replacing anything in the linked record field.

3 Likes

This topic was solved and automatically closed 3 days after the last reply. New replies are no longer allowed.