I have this DB Structure:
DATA TYPE: Order
FIELDS: Product Name, Product Base Cost and Order Total Cost
It is linked to each of this data types
DATA TYPE: Product
DATA TYPE: Surcharge
FIELDS: Surcharge Type, Surcharge Cost Multiplier
I want the Order Total Cost to be Product Base Cost * Surcharge Cost Multiplier
I know how to have a workflow run this calculation when a new thing is added to Order, but I want to be able to update the results in the Order data type should I change a value for the Surcharge Cost Multiplier thing. I want this change to flow through and update all Order things where this change is applicable.
This is a hypothetical to try to keep it simple to get at the basic thing I need to accomplish.
I use Database Triggers to monitor when a value changes, then triggers another API workflow to calculate out the cost.
In your case if there are a bunch of open orders, when you change a surcharge you would want to search for all open orders and recalculate all of them.
Same with if you modify a price of a particular product, you might want to monitor that and then search for any open orders containing that item, then recalc the prices.
Just make sure to use strict
Only when conditionals that only monitor the things you want. So you would do “Product before change’s Price is not Product after change’s Price” to only monitor the price. If you leave it open then just changing the name of the product would trigger all these recalculations of the total.
Thank you. For anyone reading this, the answer is this really can’t be done they way I’m describing but instead requires you to use the backend workflow in bubble (which isn’t visible until you enable it in settings (you can look up how to do this). Once enabled you’ll want to do something like this: Recursive workflows in Bubble (OR, HOW TO LOOP THROUGH A LIST) - YouTube
Trigger Events as described above are only available for use with the Professional Package.
I use Database Triggers on the Personal plan
Technically if you had a screen to manage the surcharges and product prices, you could do this on the front end I think…
If you edit the surcharge you could do all your searches on the client side and make changes. Not sure how it would scale though because if you get too many products to update it might take a long time and you could close out by accident without it updating all of them
That was how I was originally tackling it, but then realized it would be thousands of records.
On another note, how can I pass in a value from a custom state into a parameter in API workflow. I’m not seeing an option to do that when I add a parameter.
So when you create the API workflow you click the “+ Add a new parameter” and give it a name and type.
Then on the front end you schedule it (usually for the Current date/time) and it will ask for what you want to fill into that key
In this case my parameter/key name is “key1” and of course if you set it up as a text key you will need to feed it text from the frontend
You should post something like this here because I found my way to the post and there wasn’t an elegant solution proposed yet. Your solution is what I’m sure everyone on this string would have wanted to see.
Seems like these are two different things:
You asked if you could pass in a value from a custom state to an API workflow, so you would just do what I showed and feed it the Element’s custom state’s value into the API workflow.
I like to do that first, gather the exact Things I need and send them to be processed, it seems like those people in the thread kept doing the same searches over and over in different parts of that workflow.
I know @keith makes this plugin to store the equivalent of custom states in the backend (but I have not used it) List Popper and Friends (SSAs) Plugin | Bubble
More notably this part:
I think those in the other thread could’ve used this.
EDIT: oops wrong screenshot it’s the bullet point below that
Oh yeah. When I found it, I was searching for trying to send in a value/ref to variable on client side. My bad. Not quite the same problem. You’re right.