I’m looking for a way to write the position of an entry in a sorted query to a “Position” field in it’s database (so i can compare two entries positions).
I’m not seeing that the “Current cell’s index” is available in the API workflows to achieve this.
What is it about the sorted list that’s important? Your question here assumes a certain solution… but that’s almost certainly not the answer to your actual question… If you see what I’m getting at… What is the question?
I need to be able to reference the position of an entry outside of the context of a RG. Imagine talking about a sports team and being able to mention “4th rated sports ball team is going up against the 12th rated rival sports team”.
I have a field that holds the “team’s performance”, but I need a way to also include it’s ranking position amongst the others and still be able to reference the position it on it’s own (outside of a “Sorted by” RG).
The most straight forward method would be to simply write the position to the field in the database after each new game.
I ran into this not long ago. I was using drag/drop to rearrange items in a repeating group and wanted to save the new order into the database. The ability to access current cell index when making changes to a thing would have saved me a step or two, but I think that maybe the ability to have pagination on repeating groups makes cell index less static than it might seem.
I worked around by adding another field to my thing called tempPosition and modifying it, then saving that over to my Position field when the user saves changes. I bet there is a way to do what you want if you think about how your things are added and sorted in the repeating group.
One thought: I think you can create a group of type number that has cell index as it’s data source and then access that in each cell when saving to the database.
p.s. I’m new to Bubble myself but am trying to jump in and help where I can…
It sounds like you are in control of the sort order, so you should be able to pass your rg’s sorted list to an api workflow that loop’s on itself but uses a counter to update the records.
Here’s an example of updating a data type called random, where we set a field called number, to the sort order:
Start with an api endpoint that accepts a number (for the counter) and a list of data things:
The first step in that endpoint is to do the actual update of the data thing. It uses the sort_order to choose which thing to update, and also for the number value (for you, your team’s performance):
The second step reschedules itself, passing the same list, but incrementing the sort_order by one. It also has a condition that stops it from scheduling after it has done the entire list:
To kick off the api, use the action Schedule API Workflow (NOT Schedule API Workflow on a list) and just pass it a sorted list (I just used created date for example,) and start the counter at 1. I am showing the sort here in the workflow, but you could just pass the rg list if it has already been sorted:
Oh my, that’s elaborate! Thanks a lot for your reply.
It’s going to take me a while to wrap my head around it (API Workflows still kind of confuse me), but I’ll stumble through it and hopefully get this working thanks to your helpful reply!
Got it! Works perfectly, thanks a lot! I was initially confused about where exactly the workflows where being placed (either in API workflow or the page’s workflow, which is why I wasn’t seeing/confused about the “sort_order”).
You would still think there would be a more straight forward solution, but until that day, this gets the job done.