Workflow to subtract item from list works every other time?

So, this is definitely a me error. I have a set of multi dropdowns that update a state list. When a user selects an item in a dropdown it should be added to the state, and when a user de-selects an item in a dropdown it should be removed from the state.

My workflows are doing a fine job of adding to the state. But, when I remove items from the dropdown the state behaves strangely. If the number of items removed is odd, the state gets cleared to empty, but if the number of items removed is even the state gets updated as expected.

I have an RG that holds a list of data type: “obstacles”. Obstacles have a field for “obstacle category”.

The RG has a state called “Obstie Transfer” that holds a list of obstacles.

I have a series of multi dropdowns that displays lists of all the obstacles in each obstacle category.

When the dropdown is updated, and the dropdown’s value count is greater than the Obstie Transfer’s count for corresponding obstacles (obstacles with the same category as the dropdown), the dropdown’s value is merged with the obstie transfer’s value.

This works as it should every time.

When the dropdown is updated, and the dropdown’s value count is less than the Obstie Transfer’s value count, the Obstie Transfer’s value is updated to be: (Obstie Transfer’s value) minus (Obstie Transfer’s value filtered down to obstacles that are the corresponding obstacle category, and not in the corresponding multi dropdown).

Screenshots below. Any advice is appreciated!!!

Welp, that was quick. I was missing a step in the “remove” workflow. After the Obstie Transfer was updated to remove the items that are deselected in the dropdown, there needs to be a step to merge the dropdowns selection with the obstie transfer list again.

Sometimes you just gotta ask the internet to hear yourself I guess

Thought I solved it, but I did not.

I have a total of 13 multidropdowns, all updating a state. The state updates correctly for adding items, but behaves strangely for subtracting items.

I refigured my expressions, but I’m still having the same result: subtracting items from the state alternates between clearing the entire state, and updating the state with the expected items.

Anyone got any recommendations here? Feels like I’m misinterpreting something in my expressions or the order of operations?

@NigelG @adamhholmes @mikeloc

I’m going to cop out a bit here because it’s difficult (for me, at least) to understand exactly what you are doing. That being said, have you tried doing the removal step-by-step with the debugger to see if it can give you a clue as to why it works intermittently?

1 Like

Thanks for taking a look. I have tried the step by step.

Fwiw, I’m filtering a list of skateparks using a list of skatepark obstacles. I have a group of multi dropdowns populated with lists of skatepark obstacles. Users can select the obstacles, the selection modifies a state, and the state updates the skateparks that are shown on a map.

If I select 6 items in the dropdowns, the state is a list of those 6 items. If I remove 1 item from the state, the state clears to empty. If i remove 2 items from the state, the state sets to the 4 items selected in the dropdowns, and so on.

Without fully understanding what you’re trying to do… my first thought is, why are you trying to duplicate the multi-dropdown’s’ values in a custom state in the first place?…

What purpose does that serve?

Surly you can just refer directly to the multi-dropdown’s’ values wherever you need to?…

Or, if you must duplicate the values in a custom state, can’t you just set the custom state values to be the multi-dropdown’s’ values?

1 Like

Thanks for your time.

Im filtering skateparks on a map based on the obstacles at each park. There are 85 different obstacles currently. Originally I did this feature with checkboxes to select and deselect, but as the obstacle count grew it became an unproductive interface to display all 85 options. So, I divided the obstacles into 13 categories and redesigned with 13 multi drop downs.

I could not find a way to update the map’s list of markers without consolidating the dropdowns into a single list via the state.

Thanks again.

After thinking about this one a bit more, I’m wondering if (and I believe this is what Adam’s last point is referring to) it has something to do with referencing the repeating group and using the merged with operator when setting the custom state. I would have to test it, but something feels off there. As Adam said, have you tried setting the custom state directly to the multi-dropdown’s values?

Thanks again Mike.

I’m going to take another pass at this on friday and start without the state, and see if I can get the map to update based on the consolidated value of all dropdowns.

1 Like

@adamhholmes @mikeloc thanks for the advice guys. I wound up resolving it by skipping the state altogether, and updating the RG with the multidrops directly.

When I initially set this up it was with checkboxes updating a state, and Mike you helped me figure that out. I was assuming that I would need to build the multidrops in the same style, but they function differently because they already store lists. :upside_down_face:

13 multidrops each have a workflow that updates the RG directly.

Cuts the number of workflow events in half, and it’s much simpler expressions to change the data that’s being displayed.

THANKS AGAIN!!! :call_me_hand:t4: (shaka hand, not “call me hand”)