Forum Academy Marketplace Showcase Pricing Features

Recursive Workflows

Hey Bubblers,

Does anyone know how to set up recursive workflows in the use case of sending a long list of emails recursively? I know that Bubble mentions recursive workflows on their manual, but they don’t actually tell you how to do it.

You can make a back end api then on your front end schedule the workflow.

The last action in the api workflow can schedule another api workflow or the same api workflow with different data.

Can also do this on lists

Is this what you mean.?

That’s what I thought to, but when building how do I tell Bubble which is the next email it should send to? There isn’t a :next item function or anything

For something like a drip campaign (seems like what you’re doing) of emails I’d do a scheduled api workflow to send/schedule the first email. In your DB have this set with a field for “id” #1 at the end of the flow it would schedule the same api workflow but this time your data sent is “do search for email” with constraints of id = current api workflow “Id” + 1

So then #2 would send.

Then the logic would carry over because once #2 sent the current Id + 1 would = Id #3 so it would work perfect.

1 Like

Yeah I did do that for one of my apps, but I noticed that after 1,000 or so with 5 sec spans it times out or stops running or something

1 Like

Maybe use the first item to send the first email, then remove the first item, send again to the (new) first item (if not empty), then minus, first, minus, and so on ?

In this post a good advise from Nigel (to avoid infinite loops!) :

Hey,

@cmarchan gave me some tips for doing recursive workflows

Here a few guidelines:

  • Use schedule an api wf (not schedule a wf on a list)
  • Send the list of entries as one of the parameters of the wf (the thing marked as a list)
  • Set up an “index nr” parameter of type number. This will enable you to mark each entry of the list with an index nr (each time +1) when you reschedule the wf on itself (explained below).
  • At the end of wf actions add an action to schedule the wf on itself within an extinguishable condition that forces it to stop in the last entry (otherwise you will run into an infinite loop which can break havoc in your app …). Also, send the index nr parameter +1 so that increments each time.
  • An extinguishable condition could look like this: entry index nr < search things :count
  • Use the “index nr” to condition the actions you need in the wf

Basically it’s the same as doing changes to a list of things, but the difference is that you can taylor changes to each entry in the list :slight_smile: :computer:

3 Likes

Hi, a noob question on recursive worfklows…

I understand the basic concept for using it to make changes to a large list of things:

  1. Use API (ie backend) worfklow
  2. Start it from the client side (ie use a regular worklow to schedule an API worfklow)
  3. In the API workflow, have it search for the first item that matches a condition (like, author name = Fred) and make changes to that item (like, change author name to Mike)
  4. Then add a step to that API worklow to execute the first step again. It will search for the next “Fred”, make the change, then go on to the second step, telling it to repeat.

Question is what happens when there are no more “Fred” items to change? Does the workflow terminate once it can’t find a record to change? Or does it keep running infinitely, searching the database for “Fred” entries that don’t exist? If the latter, should I then put a “terminate this worklow” step in there to stop it once finished?

This seems like such a simple point, but I’m having a hard time finding a simple answer.