Skip to main content
December 18, 2023
Solved

Select latest added record

  • December 18, 2023
  • 2 replies
  • 0 views

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

Best answer by mathurambm639546

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

December 19, 2023

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
      )

December 19, 2023

Thank you! It worked I appreciate it