I would like to run a workflow when a button is clicked and a condition of a custom state is met.
For example: If button clicked and custom state = 1 do this, or If button clicked and custom state = 2 do that, and so on…
I’m thinking about the most efficient way of doing this…
Do I duplicate the button’s event many times with different conditions triggering the different workflows? (So 1 button with different conditions)
For example:
If button 1 is clicked and custom state is 1 then run workflow 1
If button 1 is clicked and custom state is 2 then run workflow 2
If button 1 is clicked and custom state is 3 then run workflow 3
etc.
Do I have many buttons hidden, then only make the relevant button appear when the condition is met and that will trigger the workflow required? (Many buttons)
For example:
If custom state is 1 show button 1. Then if button 1 is clicked run workflow 1
If custom state is 2 show button 2. Then if button 2 is clicked run workflow 2
If custom state is 3 show button 3. Then if button 3 is clicked run workflow 3
etc.
Is there a better way?
Which is more efficient / less resource hungry?
I hope that makes sense. Any advice would be appreciated.
[edit] I think I misread your question initially, so I just updated it to be more helpful.
I’d recommend going with approach #1 above.
For something this simple, you can also add the conditions to the actions themselves. So, when button clicked run a workflow with 3 actions. Then, on each action include an additional condition.
Note: checking for values on custom states should be really fast, so I wouldn’t think it’d matter much either way. That said, when you’re checking database values then you want to be cognizant of not running too many conditions in too many places.
There are a few more advanced ways, as well, that use Custom Events. The idea here is you can compartmentalize actions into groups that require the same conditions and put them in a custom event and run the actions up-front on the custom state.
@sridharan.s
Thank you for the response. I have used custom events here and there for workflows that I need use more than once. I may be able potentially to use it in this scenario.
Am I right in thinking that it doesn’t matter how many custom events have been created on the page, as they are only called when needed? Is this better than running actions individually when a condition is met, or does it work the same?
Also, does the amount of events you have on a page affect performance if the events are only active when a certain condition is met?
Having many custom events doesn’t cost anything because they’re never loaded client side, and if they’re not triggered they don’t use the CPU.
I think there’s a small cost to triggering a custom event from an action instead of it being an action itself, but it’s a very small cost (i.e., a millisecond most likely)
I’d count the number of conditions and more importantly the CPU cost of the calculation you’re using for that condition (i.e., looking up custom states is cheap, doing a database search to count something is a more expensive but still cheap, doing a nested search is very expensive, etc.)
In theory Bubble caches results from conditions so it doesn’t need to keep calculating things, but when they’re looking up values on a database that’s constantly being updated then it’s going to have to recalculate conditions nearly all of the time.
Anytime Bubble needs to check whether a condition is met, there’s a CPU cost for your server. So, having events whose conditions are checked has a cost even if the corresponding actions are never triggered. Two examples:
if every second you’re checking whether a database value exists, that might weigh down your system (i.e., especially when many users are doing the same thing).
Whereas, if you’re updating a timer’s time as a custom-state every second, then that’s still cheap because Bubble can actually run that client side.
Note - Bubble is subject to all of the same client-server costs as other technology systems. So, when items can be run client side, it’s cheap. When it touches the database, then it starts to have a cost.