Forum Academy Marketplace Showcase Pricing Features

Need help looping through stuff

Hi, everyone!

Here is what I am trying to accomplish:
I have a thing (say, “A”) that holds a list of things (“B”).
I want to create ‘n’ B things whose fields will be editable (via auto-binding) in a repeating group filled with different input forms.
These B things will, then, be attached to the list in the A thing.
The number of B things that should be created (n) is dictated by something else that doesn’t really matter for this topic, but is no higher than 10.

One would think: well, pretty simple! All you have to do is loop until you reach ‘n’ iterations!
Well, it just so happens that Bubble doesn’t support loops…

As a workaround, I tried making a Custom Event call another Custom Event that then calls the first one again and so on, until it reaches ‘n’, but Bubble detects my misdeed during runtime and says “no!”…

Then there are the plugins. I tried a free one that was pretty straightforward, but would not carry out all of the steps in the workflow in every iteration, skipping some steps every now and then (there were no conditions for the execution of these). Naturally, that was driving me insane and I gave up using it.

I have searched the forums, but couldn’t find that workaround involving APIs, lists and schedules. Could anyone walk me through with it or maybe show me a different solution, please? It really doesn’t have to be based on the example I gave. Just a plain, honest loop from ‘i’ to ‘n’ would be really great!

Thanks a lot!

This is very possible and Bubble does support loops. I have pasted a link below that explains recursive workflows, but a summary of your solution is as follows:
(A friendly word that recursive workflows can take a bit to get your head around, but once you do they are quite simple to replicate and extremely powerful. And should always be used vs doing something on a list).

Create a backend WF end point called something like “CreateNewBThing”.
Within CreateNewBThing you will specify the keys (new world speak for variables) that you will pass to CreateNewBThing. Reference first image below.
Then add an action to do some action like “Create a new thing”. Reference step 1 in second image below. In my case I do a number of steps so I have a separate backend WF end point for all those steps, but I believe your case would be a simple single step to create the new B thing.
Then add an action to call CreateNewBThing (itself and therefore the loop). Reference step 2 in second image below. Within this action you will specify 2 aspects of the loop: Firstly what the end step is (only when) and how to increment. My increment is based on MatchNumMin and finds the next matchNumber that meets the criteria specified and is bigger than the current (Min) number. Yours would be a much simpler counter or the like.

Reference Image one - Back End Workflow end point:

Reference Image two:

3 Likes

You, Ser, are a dear!
Thank you so much! I can’t try that out right now, but will do as soon as I get back to work and have you know the result.
Have a good day!

1 Like

Dear SerPouce,

Thank you for your time explaining this to me. I totally got it, as this is not my first attempt at recursive functions, and everything is already implemented. Sadly, though, there is no way I can test this out in my Free plan. I was hoping I could get everything working nice and smooth prior to launching the App, when I would then upgrade to a paid plan and get the data in.

By the way, what I meant by stating that Bubble does not support loops was in terms of not having an explicit action “loop”, “for”, “while” or anything of the sorts straight from the page’s workflow, which I do not understand why and think is quite disappointing. Just allowing Custom Events to call themselves would do the trick, because it worked beautifully for the first two iterations before the app detected the loop. But I am no professional programmer to get it and it’s not up to me to decide.

Again, thank you so much for sharing your knowledge!

This topic was automatically closed after 70 days. New replies are no longer allowed.