How to edit the last record created by a user ?

Options

I would like to be able to edit the last record created by a user without using the id of the last record. Does anyone have any idea how to do this?

Best Answer

  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Answer ✓
    Options

    You can use query by user_id and then sort it by created_at descending, this way you will find the record, then you can use id to edit it. Unless you specifically don't want to use id for some reason, then you need to think about so other identifier

Answers

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    @Pawel Magdanski is on the right track here. You'll want to use "query all records" to make use of the filtering and sorting functionality he is describing. In that same function call, set the output type to "single" to get the latest record and no more.

  • Clem
    Clem Member
    edited May 2023
    Options

    Hey, @Pawel Magdanski @Ray Deck thanks for your answer. I think I tested your suggestion correctly but it doesn't seem to work, probably because I executed it wrong (see picture). To explain in more detail, I have a user table and a sport_event table. What I want to do is to retrieve the last sport_event created by a user if and only if the event_sport box of the sport_event table is empty. I hope that these precisions can help you to better understand my problem.

  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Options

    I can see that in your edit record - sport_event you have Event_Sport as a text, not a variable.

    What exactly is not working?

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    You mean to want to know if the last record from sport_event for that user has a blank Event_Sport field? Or you want the most recent record from sport_event for that user and here the Event_Sport field is blank?

    In the first scenario- you get the last record from the query filtered on the user_id, and then check the output to see if is has a blank Event_Sport

    In the second scenario - you get the last record that meets both criteria.

    These more complicated and sometimes hard-to-explain situations are good use case for office hours. Xano has them on Tuesdays for their product in particular. They are free of charge.

    I run State Change, a group with office hours and a more intensive q&a forum where we focus on the hardest 5% of issues blocking shipping across all nocode/lowcode platforms . We are not free, but we focus on the toughest problems.

    EIther of these could be of service to you!