Forum Academy Marketplace Showcase Pricing Features

Allow loops on the client side

Bubble forbids recursion, and makes repetition difficult, because the shared server resources need to be protected.


But…what if we still had loops in the client side code? That wouldn’t risk the shared server at all and it could still be really useful.

For example, I need to generate unique random strings in the hundreds or thousands for individual gift cards. The elements already have the ability to generate random strings and stick them into a local custom state in a list. I could write a normal loop (repeat from 1 to 1000, new random string, add to list) and then when it’s done send it to the server to make a new thing for each code. That way the server would only have to work with lists of known length and any race conditions would be the client’s problem.

Why not generate the string on creation?

You can do this with careful management of counters in custom states.

Careful with this corner case … when you get duplicate values, i.e. the same string generated, any Bubble operation to modify the list would remove all duplicates.

Another way to get this is to use the Toolbox plugin …

List of Numbers to generate an initial list, then List Item Expression to generate another list with random strings. Duplicates will then be allowed, until the list is modified.

If you don’t want duplicates, you could cache each random string as you generate it, and check the cache before accepting.

It is possible to do loops using custom triggers to near identical workflows, I did this in the Calendar re-occurring event creation loop:

by setting up the workflows, you use the custom triggers to flip flop between the two workflows, and using some sort of check against a state to determine where you are in the loop.