How to make Conditional Workflows

I am trying to run a recursive flow to deduct user coins.
So I want to run conditional logic in the workflow, to do different things in 3 cases:

  1. user coin value > the amount that the user wants to consume.
  2. user coin value = the amount that the user wants to consume.
  3. user coin value < the amount that the user wants to consume.

Basically i want only 1 condition to run at a time.
But if i use ONLY WHEN, more than 1 condition can also run as the user coin value would have been updated before checking the condition.

So is there a way to only run the flow in case of 1 condition and exit the workflow, without going to the rest.

Use “Terminate this workflow” and give it the same condition as the previous step.

but the value would have been changed in the prev step, so the condition will not work properly in the termination step.

Break them into different events. For example if the actions run on a button click event. Have 3 events of that, each with different conditions and then the appropriate actions.

This is how I read that it was already operating :face_with_open_eyes_and_hand_over_mouth:

but to run diff events also requires the same conditions, and whenever the first event will execute it will update the value, so the condition of further events will not work correctly.
So basically the exactly same issue in this case also.

As an example, if you want to take an action based on the colour of an object.

Step 1: Take an action ONLY WHEN object is blue
Step 2: Terminate the workflow ONLY WHEN object is blue
Step 3: Take an action ONLY WHEN object is green
Step 4: Terminate the workflow ONLY WHEN object is green
Step 5; Take an action ONLY WHEN object is red
Step 6: Terminate the workflow ONLY WHEN object is red

You should be able to apply the same approach.

user coin value > x value
user coin value = x value
user coin value < x value

Have 3 workflows on the same button with conditions on the trigger event. You are guaranteed to execute only one of them since the condition is only checked once for all 3

1 Like

Sounds like you are experiencing timing issues. I don’t know the specifics of your setup but you should instead place the required actions inside workflows that update the coin value.

To make things easier you can create custom events to reuse the actions.

break the workflow into custom events for each of the conditions

really lean into custom events - there is no cost to a “custom event” in WU (cost is in the condition evaluations but no cost to run a custom event).

often I’ll even have custom events with 1 step in them or even no steps.

I have several backend custom events that I use just to store data in (like states) - I pass in the values from searches and then reference those values later on in the workflows - this makes it super easy to update 1 search without breaking the other 4 searches after it in the expression.

I rarely use terminate workflow since you can just do the same logic with custom events and it is much more performant for WU usage.

even on the page workflows you can save a lot of time using custom events - for instance 2 buttons on the page do the same thing - then they should call a custom event instead of doing the thing separately for each button - even though the custom event just has 1 step to it.

1 Like

No it is not checking the condition only once for all 3. It does it one by one, so the value is updated before checking the condition so it doesn’t work properly.

But i found a workaround: I am sending the original value as a parameter to a custom event and under that custom event I have these 3 condition which are based on the value of the parameter passed.

So it solved the problem!

1 Like

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