I’ve built a backend function that creates a list and populates it with five random articles from my Articles datatype. This is the logic I’ve used so far.
Each time I run the workflow, it returns the same list in the same order.
I’ve tried adding in a second random sort into the function as shown here, and tried “breaking” the cache through a “id <> random_value" condition in the search as described here. Neither worked.
Is this a bug? Am I missing something? If it’s a bug, is there a workaround?
@boston85719 There are currently 40-50 articles in the database, but there will be hundreds if not thousands, once the site is live. I’ve run the function 30+ times, and it produces exactly the same output in my database (screenshot below).
I’ve tried adding a few different constraints to see if that addressed the issue (including random sorting, id <> random value, sort by created date, etc.) with no luck.
Show the search you perform in the backend workflow with constraints used that are getting the same result every time…something might be wrong with it.
I’ve tried removing the “random sorting” constraint (just using the sort function) and removing the “sorted” function (just using the random constraint), and they both return the same list.
The oddest thing about this is the random item functionality works fine. It’s only random sorting that returns the same variables.
Are you refreshing the page each time? Notice the reference: Search | Bubble Docs
Random sorting
Choose this option to randomize the order results. It will be different for each user and after each refresh. It will be the same when re-running a workflow without refreshing the page.
@J805 Yes, I’ve refreshed the page each time, tried logging out and back in, and even changing the user activating the workflow (which does give one new random sort, but then all subsequent random sorts for that user are exactly the same).
@J805 Using Arc, just tried with Chrome + new user and it’s generated exactly the same list once again lol. Is there any difference in the search functionality you’re using?
Alternatively, since random item does work, do you have any idea how to build a workaround using Do Search For:random item, and then run that 5 times to create the list?
@J805 When I opened your preview in Safari, the FAQ list sorted randomly in your preview. However, when I activated my workflow in safari, it generated the same list…
I tried removing items until 5, and it was still the same list order, but including all articles instead of 5.
@J805 When I originally tried building this functionality, I tried using Search for Article: random item, and that worked (however it only created one article). Is there a workaround where I could run the random item function 5 times, and add those to the same list?
I know that would skyrocket my WU, but I’m feeling pretty desperate at this point…
Well, yeah. The WUs would be very high. You can just do that step 5 times. You said it worked once, you could technically just do the same step five times adding the results to the list at the end of the workflow. Does that make sense?
@J805 I guess it’ll have to do. Once live, the workflow will only run once per day, so hopefully, it won’t be an issue. By the way, thank you so much for going back and forth with me on this. It means a lot, truly.
I’ve started a new workflow, which allows me to populate two truly random articles.
Step 1.
Step 2. (adding in constraints to ensure it doesn’t choose the same article twice.
d
I think I’m missing some logic in step 2. Whenever I try and add new logic to add a 3rd article (either in step 2 or in a new step), the third article replaces the second instead of adding to the list. Any thoughts?
Ok, here is the example I gave before but changed to the really complicated way. This provides the random list. Does it work for you when you press it and then refresh the page and press it again?
But unless I’m mistaken, setting the custom state as you did only works on the front end. Right now, I’m using a button on the front end to test the workflow, but once I confirm the workflow creates a random list, the live version will be a scheduled recurring event that runs on the backend once per day.
As a result, I don’t think custom states will work for me
@boston85719 I’m a bit lost here. Maybe I’m misunderstanding your terminology as I’m new to Bubble.
In the screenshot you replied to, I believe the dynamic expression is the “create new article” box on the left, and the search constraints are the “Search for Articles” box on the right. As you can see, there are no constraints in the Search for Articles (outside of Sort by Random Sorting, which I’ve tried removing but didn’t solve the issue with random sort).
Are you referring to something else? The screenshot I showed you is the entire workflow. It’s only one step.