Best way to do calculations with iterative dependencies

I’m not looking for a specific answer (although one would be welcome) but more of the right direction or approach for something like this. A specific plug in? do I need to upgrade to a paid plan to get access to database triggers or back end workflows to do bubble iteration?

In my app I have Type “Item”
- Quantity (number)
- Rate (number)
- Total (number)
- SubItem (Item)
- NoOfParents (number)

The goal is to allow an item to have many subitems, and subitems to have their own subitems etc.
Think of it as list of materials (prices) to build something

-Car [qty 1] [rate $300] [total $300] [Parents 0]
-----Wheels [qty 4] [rate $25] [total $100] [Parents 1]
----------Lug nuts [qnty 5] [rate $1] [total $5] [Parents 2]
----------Rubber [qnty 10] [rate $2] [total $20] [Parents 2]
-----Doors [qnty 2] [rate 100] [total $200] [Parents 1]
----------Window [qnty 1] [rate $10] [Total $10] [Parents 2]
----------Remaining [qnty 1 [rate $90] [Total $90] [Parents 2]

The plan is to have the rate of an item equal the total of its subitems, and then multiply by its quantity and set its parent rate to the result etc… (mulitply by quantity, add to the total etc.)
And do this anytime a number changes (planning to have most as user inputs)

I have it working with ListShifter, but not consistently. Unfortunately the debugger stops when it gets to ListShifter, so I can’t follow where the process drops off.

When an input value changes, I iterate through the parents to get a list of items that are affected, and then iterate the change on the first, apply the results to the next, etc. and then iterate an update to the database with all the new values for the items affected.

The problem is that sometimes it works flawlessly and others not. I’m using custom states but suspect (hope) there is a more robust way to do this.

Anyone here have experience with computations that iterate and are interdependent? Would love to hear what you found worked and what you recommend avoiding.

I would have thought List Shifter was the way to go here. Did you know it comes with its own debugger ‘debug buddy’ so you should be able to use that to see where it’s going wrong.

This video shows you how to use the debugger

If you’re struggling it might be worth reaching out to @keith on the list shifter thread.

1 Like

Thanks for the suggestion @wrightj2 , I’ll definitely check it out! It’s probably premature to call on @keith yet, I’m under the impression ListShifter is doing everything it’s supposed to as advertised. I’m suspecting it has more to do with the asynchronous way bubble handles workflows, and I’m wondering if I’m setting states in a less that optimum way. But that’s hard to tell when the debugger times out just as the WF’s are getting interesting.

I"m going to take your suggestion and try debug buddy and see if that will give me a hint of where the glitch is. In the meantime, I’m still open to suggestions of alternative approaches if someone has already solved a similar problem.
Thanks again!

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