Order of validation of conditons vs workflow actions

I am somewhat confused and would like to clarify the worfklow execution order.
I am talking about frontend workflows.

I used to have one workflow that had steps that contained multiple conditions. And it was written in a way, that first were the actions that required the most conditions to be passed and following the ones with less. It was due to the fact, that if order was executed in another way it would actually launch all it’s steps as action 1 would create a requirement for action 2 (as it checks if action 1 result - meaning a thing in the DB exiss). This way it had worked for a year :slight_smile:

But now I need actually to split this workflow as one action is impossible to execute this way, so a question has arisen.

If I have 4 triggers on the button click
which validate different condition - and all of the have some action steps inside:

Will they all first trigger validation and then launch one by one or whenever first trigger has condition met it launches and then the next one is checked and launched.

Also - what is the order by which bubble launches steps in this case? Alphabetical?

As I feel like the only thing I can do is record somehow the stat that is before launching the flow - this way it remains stable for the whole validation. But maybe there is another method/approach.

Why would you like to have 4 triggers on the button click ? is this because you need to do 4 different validations when the button is clicked ?
If this is the case, then use “Terminate this workflow” in your workflow actions based on specific conditions so that you know for sure that if these conditions are met then the whole workflow is terminated.
You mentioned that you are using “Result of Step x”, this guarantees that Step 2 executes after Step 1 is finished because in this case its execution is dependant on the previous step.
About the workflow order execution, they are triggered sequentially but no step waits for the other until it is finished, this means that you might have Step 5 finished before Step 2 has finished execution although Step 2 is always triggered before Step 5.
If you would like to make sure that the execution is done in the right order, then use “Custom Events” instead of “Workflows”.

Hope this helps !

1 Like

Thanks @ahmed.elkaffas .
The issue I have is more less like below:

Trigger 1 - if there are more than 2 activities and dropdown isn’t X → Actions… (not our current concern here)
Trigger 2 - if there are more than 2 activties and dropdown is X and there is Activity X → Actions … (that create activity X with specific paramters)
Trigger 3 - if there are more than 2 activities and dropdown is X but there isn’t any X Activity → Actions… (that create activity X with specific paramters)

So I want to be sure - that never ever the Trigger 3 launch before trigger 2 creating an activity that later leads to passing the criteria of trigger 2.
I know I can make them as a custom workflows, but I want to be sure that the criteria are validadated before any action takes place, never after. As every action has impact on some of the criterias.

This is a shorter, hopefully more visual description of my issue.

There’s a lot of possible reasons to use 4 events on a button click. Basic case is, for example: field = yes, update to no, field = no, update to yes / field contain X, remove X, field doesn’t contain X, add X. Doing it in one trigger will cause issue because if the first action with condition is field is yes, switch to no, this mean the second action is no switch to yes… result: it will always be yes. This is a basic example with only two conditions, but in some case there’s more conditions, so more trigger can be needed. (But there’s also some existing workaround for theses case sometimes)

Also, this can help saving on WU by evaluating the case on the trigger to avoid each step of a WF to do is own validation (including terminate this workflow where you add another action with a conditionnal that could cost WU).

2 Likes

custom events act as “chunking” of logic in a workflow

custom events are very useful because:

  1. actions within a workflow are completed up to the point of the custom event trigger
  2. the custom event is triggered and completes all of its actions
  3. after the custom event the original workflow resumes and completes the actions after the custom event

you can also nest custom events within each other to further the above forced order of operations

if you have an api workflow you can put it in a custom event to force it to trigger at a specific step in the workflow

you can also pass information in and out of custom events

custom events do have a limitation though in that you cannot repeat upon themselves (cannot loop CE1 to CE2 back to CE1 - instead you’d need an api workflow to break the chain).

the workflow steps try to process at the same time unless there are dependencies or custom events
api workflows always process immediately within a workflow regardless of position - unless having a dependency

1 Like

Thanks for the elaborate answer, but I feel lost.
I want a simple answer.
If I have 4 conditions trigger set of actions and want to be sure the conditions will be evaluated before any action will take place take place → which approach should I take?

I know that there are custom events, I know bubble pretty deep, but here I do not know what is the order of execution.

Trigger A (condition X) → Action 1, 2, 3.
Trigger A (condition Y) → Action 4, 2, 1.

So will it go:

Variant Alpha:
Trigger A(conditon X), Trigger A (condition Y), Action 1, 2 ,3 (if condition X was passed), Action 4, 2, 1 (if condition Y was passed).

Variant Beta:
Trigger A(conditon X), Action 1, 2, 3 (if condition X is passed), Trigger A (condition Y), Action 4, 2, 1 (if condition Y is passed).

Variang Gamma:
Custom event 1: (condition X), Custom event 2 (conditon Y).
This one is flawed as it requires me to align them in perfect condition agains the triggers overlap. I want all the triggers to be assessed in the same time - as at the moment of assessment - only one can be valid. As if Event 1 Conditon X is passed it will be executed and can lead to passing condition Y, and I want to validate them all before the flows are launched, not after.

This is the question I am looking to be answered.

if you need to evaluate the conditions using the same data before it is potentially changed by a workflow then just store the data in either a state or a custom event parameter

ie button clicked
save data to evaluate as a state or trigger a custom event and map the data to it
then have child custom events referencing the “frozen” data properties

1 Like

The case I have blocks the use of state, so custom event parameters is a way to go. But it would actually be very useful if we can make a simple if else statement and know order of execution. Thanks Mitch!

custom events are basically a way to do the if/else statements

if condition is true then run custom event
if condition is false run a different custom event (which potentially has a nesting of another 2 custom events with the same yes/no branching)

I use custom events a lot since they are so versatile
sometimes I just use them to hold data or do basic math or data manipulation - no actual workflow steps just send data in and get data out

for example today I created a custom event that allows me to pass in up to 5 date values and returns them as a list (of which I then get the lowest date value)

sure you can do this with the parenthesis expression builder (search plus search plus search etc) but if you even needed to change a dates source then you’d have to rewrite the whole expression

with a custom event each expression can be held separately which makes it very easy to update when logic changes

1 Like

Yeah, but this solution still doesn’t give me the thing I need - enforcing the assessment is always before any action. As if you say I have to nest, it means I have to follow some order of execution. I want to be able to evaluate first all 5 criteria and then if any pass - launch ones that pass. Don’t want to think how to allign them so they are alligned that always event 1 is the “most demanding one” so it is evaluated first, then one that requires less etc. I want to build evaluation chronologicallly, like in my example, and then run only the action, which I need.

Actually I think in the end I will use mix of what was said.
As I have to setup a custom workflow, but as parameters I will send data I later use for validation.
I still use in this case flow where I have more steps and in most cases we do not executer more than 30% of them, but this way I enforce stable moment of condition validation so no action can impact this validation by changing the current state.
Thanks for advices, made me solve this issue.

Custom WFs already do a great job solving sync/async in Bubble WFs.

The alternative is to run your own JS. You can use the Toolbox plugin. Pass the values to a Run Javascript action, do your processing then pass the results to a Toolbox J2B element function which triggers an event to run a WF. Or you could write a plugin.

1 Like