Infinite loop troubleshooting

I’ve used @cmarchan’s tried and true recursion strategy several times throughout my app. Today, however, I threw an infinite loop and I can’t figure out why. I’m trying to send a text to a list of leads using the ClickSend plugin. Here’s my setup:

On the backend, I have 4 keys: the leads, text message (“input”) being sent to each lead, index, and count.

The first step includes the content and to/from numbers.

In the second step, I’m scheduling the API workflow to iterate through my list of leads only when index < count.

Finally, when I trigger the API workflow on the frontend, it’s set to fetch the user’s text input.

Do I need to include the index < count for step 1 of the backend workflow as well? Otherwise, I’m really at a loss for why this is happening…

1 Like

Hello @sydney22

The list of leads shows as a list parameter on your event but on each run a search to the dB is performed. Thus …. the flow is not iterating through each fed list item.

Try naming that list to “leads” instead of lead. It will help to distinguish a list from an item.

Then on each run use “leads: each item’s phone item#index”

Just make sure that when you are re-scheduling the flow on itself to add +1 to the index. This way you will be looping through each list item. :smiley:


Thanks, @cmarchan! Just for my own sanity, does this setup look better?

That last picture I initially had the List to run on as leads (I misunderstood from your post) and it threw another infinite loop. I adjusted it to Do a search for: Leads and that seems to be the way to go as opposed to this:

Hello @sydney22 !

Thanks for the like and solution!

Please note that recursion works when you schedule a flow on itself … not a flow on a list :pensive:

Try rescheduling the flow on itself with “schedule the same flow” (you know what I mean :sweat_smile:) … with the exact parameters as you kindly show on your good and bad pictures.

You will be passing leads through the leads parameter.

And the brake will do its job not re-scheduling the flow past the leadsCount in order to avoid an infinite loop (index < count … or index <= count) :smiley:

1 Like

Ahhhh…this line:

Please note that recursion works when you schedule a flow on itself … not a flow on a list :pensive:

should be required reading for Recursion 101 in Bubble. That makes a lot more sense now. Hopefully third time is a charm!

1 Like

Bingo!!! :sweat_smile:

1 Like