Skip to main content
Known Participant
Dec 18, 2023 8:43 PM UTC
Solved

Select latest added record

Hi All,

I have a query that returns documents with a specific name, sometimes by mistake we will have 2 or 3 files/documents with the same name, I want to make sure that my query selects the latest one added instead of the first one that it finds, how can I accomplish this?

Right now if I have 3 files with the same name it picks the first one added since its the first one the query finds.

thanks in advance

Inspiring
Dec 19, 2023 1:23 AM UTC

Hi Maria, you can sort the query results descending either by 'id' (PK) or by the 'created on' field to get the latest added document.

a!sortInfo(
        field: "id",
        ascending: false
      )
      /*OR*/
a!sortInfo(
        field: "createdOn",
        ascending: false
      )

2 replies

Inspiring
Dec 19, 2023 1:23 AM UTC

Hi Maria, you can sort the query results descending either by 'id' (PK) or by the 'created on' field to get the latest added document.

a!sortInfo(
        field: "id",
        ascending: false
      )
      /*OR*/
a!sortInfo(
        field: "createdOn",
        ascending: false
      )

Known Participant
Dec 19, 2023 1:49 PM UTC

Thank you! It worked I appreciate it