Can I trigger a workflow anytime a custom state changes?

I have a page with some buttons that set custom states. The data source of a corresponding repeating group (RG) changes in response to these states.

For example, if a user click “answered” then only answered questions will be displayed in the RG.

The RG contains videos elements. I have a workflow action “pause all videos” that I want to run anytime a state changes so that a hidden video does not continue to play.

I currently have two states: Answer Status (with yes/no states) and Question Type (with 4x states: all, general, behavioral and role).

I could have 6x workflows:

  • When Answer Status = yes then pause all videos
  • When Answer Status = no then pause all videos
  • When Question Type = all then pause all videos
  • When Question Type = general then pause all videos
  • When Question Type = behavioral then pause all videos
  • When Question Type = role then pause all videos

But I’m hoping to reduce the number of workflows.

Can I do this with two workflows?

  • When Answer Status changes then pause all videos
  • When Question Type changes then pause all videos

Or with one workflow?

  • When any one of Filter Group’s states changes then pause all videos
  • Note: Filter Group is the name of the group element that stores the states
2 Likes

Use a conditional workflow.
Only when X happens

In the settings there is a one time and every time option. Select every time.

Yes, but what is X?

Here are my choices:
image

Per screenshot above, I don’t see how I can construct a statement with a “changes” argument only an “is” argument.

Unfortunately there is no option in Bubble to run a workflow when a custom state’s value changes - which is a shame as there are many cases when being able to do this would be extremely useful.

There is a simple enough way to achieve the same thing though…

Rather than using a single custom state, use 2, and then check one against the other, and anytime the 2 values don’t match you can trigger a workflow.

So for example in your case you could have 2 states for the question type:

Question Type Main
Question Type Check

Use Question Type Main the same way as you have been, setting it when users click on a filter button, and using that state to determine what questions to show.

Then, set up a workflow to run ‘when a condition is true’ and that condition will be when Question Type Main is not Question Type Check.

So in other words, any time the two states aren’t the same (i.e. when the main one changes) the workflow will run (make sure you select ‘run this every time’).

Then, in the workflow you can run whatever actions you need to, e.g pause all videos, then be sure to set the second state (Question Type Check) to the new value of Question Type Main, so that the 2 match once again, and it’s ready to trigger again when the main state is changed.

7 Likes

@adamhholmes this sounds great. Just to make sure I understand how to implement this correctly, for my Question Type Check state would I want that to be something like “apples” so that it’s never a matches and the Question Type Main and thus triggers the workflow every time Question Type Main changes?

No, they need to start with the same value (so they are the same to begin with, and the workflow will run whenever they become different i.e. when one of them changes)…

They can either both be empty to start with, or can both have a default value of (for example) ‘all’

so to start with:

Question Type Main = all
Question Type Check = all

They are the same.

Then, when a user clicks on a button (e.g. General), you set the value of Question Type Main to general.

That makes your repeating group now display the general questions, and it also means that the 2 custom states no longer match, i.e.

Question Type Main = general
Question Type Check = all

This mismatch will trigger the workflow (as it’s set to run anytime Question Type Main’s value is not Question Type Check’s value).

So then you pause all videos in the workflow, and set Question Type Check’s Value to ‘general’ so it now matches Question Type Main again, and is ready to trigger the workflow again upon the next change to Question Type Main.

@adamhholmes thanks for your patience but I’m still not following. I don’t see why it’d be a problem to have the states mismatched at the outset.

  • when page is loaded and initial state established, all =/= apples so videos paused
  • when general is clicked, general =/= apples so videos paused
  • when answered is clicked, answered =/= apples so videos paused
  • when unanswered is clicked, unanswered =/= apples so videos paused

All of the above are desirable behaviors.

But I tried implementing such a workflow and it didn’t work.

So I’m wondering,

  • even though the “only when” field above says “Filter Container Question Type is not Filter Container Check”
  • in practice, does it really mean “only when Filter Container Question Type was equal to Filter Container Check but is no longer equal to Filter Container check”?

That would explain why my workflow isn’t working as I’d expect and I’d need to start with matching states. But if I read the “only when” condition literally that doesn’t seem to be what it says.

Thanks again!

If you start with mismatched values then the workflow will immediately trigger on page load - which in your specific case is probably not much of an issue, but more generally for this kind of application there isn’t much point in that, and it could be undesirable in many cases. Plus if you then change the second value to match the first one (which you need to do for it to work again) you may as well just set them the same to begin with.

  • in practice, does it really mean “only when Filter Container Question Type was equal to Filter Container Check but is no longer equal to Filter Container check”?

Having just tested it again for myself, it does appear that that is the case - i.e. until the 2 values are realigned the workflow will not trigger again, and will only run if they were the same, and no longer are.

If I use a single, unmatched value (e.g apples) for the second state and don’t match it back to the first after the workflow, the workflow only runs once, so it must be, as you suggest, that it’s only when Filter Container Question Type was equal to Filter Container Check but is no longer equal to Filter Container check.

Try it for yourself to test it - I just had a test version of this scenario working perfectly - although I was only using one pair of custom states (a main one and a check one), not 2 as you are in your app - so I’m not 100% sure if it will work with a single workflow and an ‘or’ expression (it may do, you’ll have to test it), or you may need to run 2 separate workflows (1 for the questions states and one for the answer states).

2 Likes

Thanks for the help! My testing seems to confirm your conclusion that such a workflow is only triggered when the state used to match but no longer matches.

Everything seems to be working as desired now. Thanks again!

1 Like

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