Toggling a custom state between 'yes' and 'no'

I am trying to toggle a custom state between ‘yes’ and ‘no’ in a workflow.

  1. In step 1, if the state is ‘no’, change it to ‘yes’.
  2. In step 2, if the state is ‘yes’, change it to ‘no’.

However, this always results in ‘no’. My current solution involves adding another custom state: when step 1 is triggered, it sets the state to ‘yes’, so step 2 is not executed. Then, in step 3, I set the additional custom state back to ‘no’. While this method works, it feels cumbersome.

What is the proper way to make toggling work? Is there any way to implement an IF-ELSE condition?

Can you give a screenshot of your workflow?

Here is the screenshot
Step 1

Step 2

The workflow:

image

Just set up two workflows on that element and conditionally run one or the other on yes or no.

Is the simplest workaround for Bubble’s lack of inline conditional logic, just bear in mind that if you make lots of these and have many workflows, bubble won’t scroll to the workflow properly (or open one) when you click to edit workflows on the element.

1 Like

It is possible to do this, but not by using two actions in the same event (trigger), since the last one will always be the final result. Instead you should have each action executed by an event and the conditional should be inserted at the event level. That way only one event would be executed.

However, for these cases, the best approach is to use double negation logic (or logical alternation in this case). So, in this case you use only one event, without conditionals, and the only action in this event should set the Custom State value by checking if “the boolean state of the element is no”.

This will result in:
1 - The current boolean state value is no? If it is not, it will be toggled to no.
OR
2 - The current boolean state value is no? If it is, it will be converted to yes.

1 Like

Sorry, I don’t really understand your method here. Can you please explain better?

The first method mentioned, using two triggers.

Trigger 1 (set state to yes when current value is no)


Trigger 2 (set state to no when current value is yes)




The second method, using one trigger with logical alternation to toggle the value.

In this method, if the current value is no it will be evaluated to yes, if the current value is yes it will be evaluated to no.

2 Likes

It works!!! I really like your second method. I never thought it could be done this way.

Thank you very much for your help and for spending time on the example. I really appreciate it.

1 Like