Updating main thing with live subtotal

I’m building a recipe database, with type ‘Recipe’ that includes ‘Recipename’, ‘RecipeIngredients’ (list of ingredients with Qty), ‘User’, Calories. The list of RecipeIngredients populates my RepeatingGroup. I use the plugin “RepeatingGroup Tools (Bdk)” to extract line by line info from the repeating group.

Each line in the repeating group has it’s own calculation: Ingredient’s Calories * Qty * Unit Value. I then use the plugin I mentioned to subtotal each RG’s line, to a total that shows the recipe’s total calories. This calculation updates live, and is always accurate - no issues there. What I would like to do is write this live calculation to the database of the current recipe’s calories. This is where I’m seeing all kinds of strange behavior!

Workaround 1: I created an input field that pulls the value of the plugin’s column sum (which is the same exact metric I use to populate the recipe’s total, which again, is accurate) - this input field stays accurate, but I can’t write it to the database, because it’s input numbers are not considered ‘inputs’ as it was not filled out by a human, even though it has a dynamic, ever changing value accurate to the recipe.

Workaround 2: I tell it to do a count of the items in the repeating group, and if Count is less than or equal to 0, it uses the plugin’s column total - again, no dice.

Workaround 3: I attempt to flag each instance of changing/updating the recipe, to trigger an update of the calories total, but at a certain point it fails to update. Everything from ‘when plugin’s column total is less than the current recipes calories, update current recipe’s calories with the plugin’s column total’ to ‘when the repeating group is visible’ or ‘not empty’ update etc etc.

All this to say - I feel the solution is much more straightforward and simple than anything I’ve attempted with my workarounds. Just the fact that I have text field and an input field that remain 100% accurate & live updated with the recipe’s calories - but I haven’t been able to write those values to the DB - tells me I am close but not quite there.

Any ideas, dark horses I haven’t considered? If you’d like to see the actual app behind-the-scenes let me know and I can dm you the link.


1 Like

To give a TL/DR: I have no problem getting a calculated total from a repeating group to display it on the page - but it has been more difficult and workaround heavy trying to get that calculated value to accurately and consistently write to the DB.

1 Like

hey @msgiblin

We are working on a plugin to handle lists and do some calculations, I honestly don’t know how much it can help you, but if you are interested, I can authorize the current version (alpha) to your app.

We can add the features you want to it if needed.

1 Like

I’d love to take a look at what you’re working on!

1 Like

In each of your line items have it so if any of the inputs change it recalculates it’s own value. A few “When input’s value changes” events and then recalculate (make sure to refer to “This input” in the calculations)

Then just have a database trigger check if the line items Value before is not After and re-sum all of the items. It would be Make changes to a thing → line item’s After Change’s Recipe (or whatever the parent name thing is)

Your line item datatype should have a field referring back to the parent Recipe or main-thing to avoid having to search for the main-thing that contains that line item every single database trigger.