Forum Academy Marketplace Showcase Pricing Features

Populate a DB with data from another DB when a button is clicked

I have a dataset called “Users” with all my users.
I have a dataset called “Pairs” with two fields: UserA and UserB of the type “User”

Each week i want that when an admin clicks a button, these users get randomly paired and these pairs saved at “Pairs” DB.

So for example:
Users:
Tom
Jerry
Bob
Alice

After clicking a button, the “Pairs” db got randomly populate as follows for example:

UserA, UserB
Tom, Bob
Jerry, Alice

Is that possible? Can someone point me any direction on how to accomplish that?

tks in advance

Hi there, @petrybr… as with all things Bubble, I’m sure there are a number of ways to do what you have described, and a way that comes to my mind involves a backend workflow and one additional field (a user list) on your Pair data type. Oh, and bear with me on this one because, while I think this suggestion is a reasonable one, someone could easily come along and rip it to shreds for some reason that isn’t readily apparent to me. That being said, here’s what I’ve got.

My Pair data type looks like this…

I have a backend workflow called create pairs that takes a user list as its only parameter.

I have a button called Create Pairs that calls the backend workflow and sends a user list that is a search for users with no constraints.

The backend workflow has six steps. Step one creates a new thing in the Pair data type, and it sets the thing’s available users list to the user list that was passed in to the workflow. It also sets the thing’s User A to a random user from that user list.

Step two makes changes to the result of step one, and the change it makes is to remove the user that is now the thing’s User A from the thing’s available users list.

Step three makes changes to the result of step two, and the change it makes is to set User B to a random user from step two’s available user list (which no longer contains the user in User A).

Step four is the same as step two, except that it makes changes to the result of step three, and the change it makes is to remove the user that is now the thing’s User B from the thing’s available users list.

Step five calls the backend workflow again, and it passes in a new user list from the result of step four (which is a list that no longer contains the users in the thing’s User A and User B). This step only calls the backend workflow again when a count of the users in the available users list from step four is greater than 1 (so, the backend workflow will stop running when there aren’t enough users left to make a new pair).

Finally, the last step in the workflow tidies up a bit by clearing the thing’s available users list because there is no need to keep that list around after the thing has a user in its User A and User B fields.

So, there you go… that’s a potential solution that came to my mind. Full disclosure, though… I didn’t actually run that workflow because I created the example in a sandbox on the free plan. Anyway, it’s probably way more than you wanted, but maybe it’s good food for thought… at least until someone comes along and tells us why it’s the worst suggestion ever. :wink:

Best…
Mike

2 Likes

Hello dear internet stranger @mikeloc

Thanks for not only sharing one idea, but also guiding how to do it step by step!

Im also in a free plan now so cant test it, but the logic makes total sense! If what i’m planning to develop goes to a paid plan, I test it and update the results here!

My only concern is scalability, talking about a table with thousand of users going through this process! But for MVP sounds a perfect solution! tks again

1 Like