Filter bundles based on the presence of a value in an array of objects

:bullseye: What is your goal?

I want to filter Make bundles based on the presence of a specific value inside an array of objects, and then retrieve only one field (the email) from the matching bundles.

More specifically, I need to keep only the bundles that contain at least one object in an array with a specific id value, and discard all others.

:thinking: What is the problem & what have you tried?

Each bundle contains an array of objects (for example Tags), and each object has an id and a name.

The issue is that:

Each bundle can contain 0, 1, or multiple objects in the array

I need to check whether at least one object in the array has a specific id value

Standard Make filters don’t seem to work as expected when filtering based on a condition inside an array of objects

I’ve tried:

Using standard bundle filters

Using contains() and map() on the array

Comparing mapped values to a static ID

But I can’t reliably filter bundles only when the array contains an object with the target id.

:clipboard: Error messages or input/output bundles

Here is a simplified example of the bundle structure returned by the module:

{
“Email”: “example@email.com”,
“Tags”: [
{
“id”: 1716937,
“name”: “client_novembre”
},
{
“id”: 123456,
“name”: “other_tag”
}
]
}

I want to keep the bundle only if one of the objects in Tags has id = 1716937, then extract the Email field.

:camera_with_flash: Screenshots (scenario flow, module settings, errors)

You can use contain with map in a filter to check the Tags array if it contains the specific Target ID (1716937).

For a single ID:

{{contains(map({{Email.Tags}}; id); 1716937)}}

For Multiple IDs:

{{contains(map({{1.Tags}}; id); 1716937; 123456)}}

Let me know how it goes!

Hello @Karmic

Thanks for your help, I really appreciate it.

I’ve tested the solution using contains() with map(), but I’m still stuck.
The main issue seems to be related to the structure of my data after the Array Aggregator.

At this stage, I have one single bundle containing an Array[] of contacts, and each item inside this array has its own Tags[] array.

When I use map(), I’m not able to correctly access the nested Tags array inside each item of the aggregated array.
Because of that, the map() expression doesn’t return the tag IDs, and the result is always empty.

So effectively:

  • map() works on the top-level array

  • but I can’t reach Tags[].id inside each array item

  • which prevents the filter from detecting the presence of id = 1716937

  • and therefore I can’t extract the corresponding email addresses

If you have a recommendation on how to handle nested arrays after an Array Aggregator (for example whether the filtering should happen before aggregation, or how to properly reference nested arrays in map()), I’d be very interested.

Thanks again for your time and support !

Welcome to the Make community!

Filtering before the Aggregator is the correct approach.

Here’s how to do it by ID or Name:

I’d recommend going through the Make Academy if you haven’t yet!

Here are some useful links and guides you can use to learn more on how to use the Make platform, apps, and app modules. I found these useful when I was learning Make, and hope they might benefit you too —

Learn Make

How-Tos

Useful to Know

My Custom App — Absolutely Free!

Save development time and operation credits with these utility modules: Chunk Text; Chunk Array; Chunk Words; Multiple Find & Replace; Collection to Array/String List; Execute JavaScript; Estimate Tokens; Calculate Difference Between Two Dates; Get Next Business Day (with holidays); List Upcoming Dates of Day of Week; and more!

— @samliew

2 Likes

Thank you so much @samliew , the problem is solve :trophy:

1 Like