Forum Academy Marketplace Showcase Pricing Features

Using 'for loop' logic to process the contents of a list to generate another


I’d like to process a list of item things called ITEM LIST with an Item name and an instruction and generate another that summarizes it called SUMMARY LIST.

The fields in ITEM LIST are Item Name and Instruction. Instruction can be one of 3 strings: “Opening”, “Plus one” or “Minus one”. The order of the items can be totally random. See below:

The SUMMARY LIST that I want to generate should look like this at the end:

I can easily do this with a “for loop” but I don’t know how to structure its equivalent in Bubble. Suggestions are really appreciated!


1 Like

Hi Alex,

How did you go with this?

Some questions which influence how to approach a solution …

  • Can you explain more about the problem you want to solve?
  • What does the data represent?
  • Can there be more than three Items A,B,C?
  • Can there be more Instructions?
  • Do you want the result in a database table, a custom state, repeating group, text summary?
  • Can the numbers in the summary be in a text form?
  • Does this need to happen on the server?
  • Can the rows in the summary be built up as the data is created and edited?

hi Mishav,

Sorry, the background of the problem I’m trying to solve and the meaning of the data was in a larger question that I then broke down into parts but did not include in the parts.

In simple words, the larger context is one in which I want to manage the assignment of assets (e.g. a computer or a piece of software) to people based on requests for adding or removing business roles. The items in the tables above represent those assets. The mapping between requested roles and required assets is kept in a table in bubble, which I already have.

The list in the first table is the result of creating those records based on the requested roles and the map of roles to items.
Opening values represent assets that the person already had when a role was requested to be added or removed.

There can be hundreds of different items (A B C …)
There are only three types of “instructions”

  • Opening
  • Plus One
  • Minus One

Ideally, the result, which is the SUMMARY LIST s/b in a repeating group. There is no need to persist it further once the request has been processed. But the SUMMARY LIST is still not the end of the game. I’ll need those values to create a table with values that need to be persisted.
Since I have to process the numbers further, I’d rather have the result in numeric format.

I’d rather have all this happening in the server.

It is possible to build the rows in SUMMARY LIST as the data is created / edited. If that were the case, the first rows that would impact the result are those in ITEM LIST with “Opening”. The values for those items in Plus One, Minus One and Net would be zero and the value of Closing would be equal to Opening.
If I add a role in the request, all the items (A, B, C, etc) required by that role would get an increment in the column Plus One, and the Net and the Closing be recalculated.
If I remove a role, all the items required by that role would get a decrement in the column Minus One and again the Net and Closing would be recalculated.

Of course, if I remove the request to add a role or the request to remove a role, the impact on the respective rows of the items required by that role would need to be updated.

I hope this answers your question.
Thank you in advance for your support!


This is likely a good approach, avoids the need for looping to create (and maybe remove) the summary rows.

The summary rows can be updated as data changes, or in bulk with a “modify list of things” workflow action.

Non-persisted rows could be created as lists in custom states, but as these lists don’t allow duplicates I think this wouldn’t help.

Sounds like you have a good sense of what needs to happen. Do you have any pain points?

Hi Mishav,

I think the pain point is about the how, i.e. how to populate the SUMMARY LIST, either during or after the ITEM LIST is created. If it’s during (is it better this way?), I need to know how to configure it, so a row is given by an item and a column by an equation. It it’s after, I need to know if a) I need to cycle through the ITEM LIST multiple times, one for each “Item”. that has not been processed yet or b) I can generate the SUMMARY LIST in just one pass through the ITEM LIST.

If the SUMMARY is generated after the ITEMS have been completed, then I need to understand how to deal with lists that are larger than 50 items (the subject of another of my posted questions)

Many thanks in advance for your insights and help,


Hi Alex,

You can try more than one approach, then pick which fits best.

That is a good idea for a non-persistent summary. Note that the values aren’t going to be reusable elsewhere.

For example, a repeating group:
Type of content: text
Data source: search for ITEM LIST's Item:unique elements
Then in the cell:
Item: Current cell's text
Opening: Search for ITEM LIST:count,
search constraints:
Item = Current cell's text
Instruction = Opening

[quote=“alex5, post:5, topic:11395”]
how to populate the SUMMARY LIST, either during or after the ITEM LIST is created. If it’s during [/quote]

You have a workflow to create a new ITEM LIST? Add another action on the same workflow to modify a SUMMARY LIST row. Turn on “create if it doesn’t exist” and increment the counts by setting them to the previous value + 1. You may need a workflow action for each Instruction type, to specify the logic of which counter to increment.

Options on how to do this:

  • Effect a loop for each Item unique value. Bubble actively discourage this, but you can use the event “Do every 5 seconds”.
  • Schedule API workflow on a list. There are lots of posts on how to do this.

You could also have a hybrid approach: create the summary rows as each item row is created, then you have the rows in the summary to “Make changes to a list of things” to update all the counts.

@alex5, you might also consider this solution by @louisadekoya

1 Like

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