Workflow that adds thing if thing doesn't exist and removes it if it does

I’m building an app where Users can save Events. I have a “Save Event” button that I want to use for both saving and un-saving an event.

(I’m using conditional statements to change the color and text of the button, depending on if the event if saved in the User’s List of Saved Events or not, so that the “Save Event” button turns into an “Remove Event” button depending on whether or not the User has saved the Event.)

If the user clicks the button and they DON’T already have the event saved, I want to add the event to their List of Saved Events. If they click the button and they DO already have the event saved, I want to remove the event from their List of Saved Events.

The Workflow that I’ve tried looks like this:

  1. Check to see if Event is in User’s List of Saved Events. If it isn’t, then add it.
  2. Check to see if Event is in Users’s List of Saved Events. If it is, then remove it.

The problem is that I want to only do one of those operations, but currently in the Workflow they run in sequence, which means that the event gets added (because it doesn’t exist) and then removed immediately afterwards (because now it does exist).

I can do this using custom states on the page, and I can also do it by show/hiding two different buttons, but ideally I want to do it in a simple Workflow using a single button so that I can easily create an isolated reusable element.

Does anyone know how to do this kind of “add if not exists, remove if exists” logic in the simplest / cleanest way?

Thank you!

Actually it looks like I can do this by adding the condition to the Workflow trigger itself (the “When” statement), and by using 2 different Workflow triggers. One trigger only fires if the User doesn’t have the event saved, and the other trigger only fires if the User does have the event saved.

I tested it to make sure that the triggers don’t check sequentially (which would be an issue), but it appears that only the correct one runs.

I do have to use two Workflow triggers which is slightly more work than just having 1, so if anyone has a better solution I’d be glad to hear it! But if not, this does technically solve my issue for now.

Hi there, @steven13… just FYI, but what you described (using two workflow events with conditions at the event level) is essentially the best practice on this one given the way workflows and actions within them operate. So, in other words, well done figuring this one out, and you should be good to go here.


1 Like

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