How to filter multiple conditions of array content

I am not sure how to efficiently handle some conditions.

I have a user which updates its preferences about receiving or not 2 newsletters (named: Dogs and Cats). When the user changes his/hers preference, my trigger outputs me a previous situation and the current situation of that user.

My trigger gives me this type of data:

{
  "current": {
    "email": "email@email.com",
    "name": "Test",
    "newsletters": [
      {
        "id": "67c9b991159234000122c01e",
        "name": "Dogs",
      }
    ]
  },
  "previous": {
    "newsletters": [
      {
        "id": "67c9b991159234000122c01e",
        "name": "Dogs",
      },
      {
        "id": "67d54f71792e6b00019aae19",
        "name": "Cats",
      }
    ]
  }
}

I am only interested in the newsletter array.

The above example is when a user had both newsletters active (Dogs and Cats) and disabled only Cats, remaining only with Dogs.

I want the scenario to execute ONLY if the Dogs newsletter preference has changed. But my trigger activates whenever something gets updated from the user side so I can’t stop the trigger to activate, I need to filter right after the data arrives.

The newsletter array is empty when no newsletters are active.

I created this summary table to check when I want the scenario to execute and where I don’t. In these 4 cases I do not want my scenario to continue.

Column 1 Column 2 Column 3 Column 4
PREVIOUS CURRENT CONTINUE SCENARIO?
empty newsletter array only Cats enabled NO
both newsletters are active (D & C) Cats gets disabled NO
only Cats are active Cats get disabled NO
Only Dogs are active Cats get enabled NO

i decided to check if newsletter array has ID of the two newsletter. I tried like this (the filters are more than that but could not fit into a screenshot):

I put those here:

But it is not working.

My scenario should continue in the “fallback” route if any of those conditions are met.

How to do that?

1 Like

I still haven’t found a solution and I am thinking that filters ARE OR are somehow overlapping, there are no parenthesis to handle them so there should another way to filter multiple conditions…

1 Like

You’ll need to use the map function to extract an array of ids.

To do this, you can use the built-in function map — “Returns a primitive array containing values of a complex array. Allows filtering values. Use raw variable names for keys.”

{{ map(complex array; key;[key for filtering];[possible values for filtering separated by a comma]) }}

e.g.: (paste this into the filter field)

{{ map(1.previous.newsletters; "id") }}

Then, you can use the “Array Operator: Contains” operator.

For more information, the function’s documentation can be found in the Help Centre. You should also complete the tutorials in the Make Academy.

Hope this helps! Let me know if there are any further questions or issues.

— @samliew

P.S.: Investing some effort into the Make Academy will save you lots of time and frustration using Make.

2 Likes

Ok I got it! Can the “condition” field of a filter contain complex formulas? So not only map.

Like

if(contain(map()))OR(parameter}AND and so on

1 Like