Filter arrays to get a subset of arrays

I’ve taken all the classes; watched all the videos on working with data… lots of great information, but I feel no closer to solving my issue. All the examples seem to assume that you somehow know the item # you’re after (i.e. record 4) or that you want the first or last item (which seems useful if you have a sorted sample so that you can get the lowest/earliest item or the highest/latest item) - but I want the whole array where a key = a (variable) value.

I am using a vendor-provided API and an HTTP module to return arrays of future ‘bookings’ during a specific time period (this specific API only allows me to return records based on a from and to date). Since I only want all the records for a specific driver, the results contain a lot of records I don’t need. Ideally, I want to filter for a specific driver’s records, while keeping the array intact. Is there a way to do that? The image below shows enough of the array structure to understand its complexity. As you can see, there are a lot of collections within each array. Is there a way for me to return all the array record(s) that have a driver 2701234, for example? In the final version, the scenario is triggered by a driver completing a booking, so the actual driver # will be a variable = to the driver who just completed a booking. I hope that makes sense.

1 Like

Got it! I used an Iterator and an Array Aggregator after the HTTP module and put a filter in between the two that filtered on the Driver Ref #. Yes! Next challenge… I’ll be back soon with more questions - no doubt!

3 Likes

Hey @Barbara1

Glad to know you figured it out. Just wanted to suggest that you can save 2 operation from iterator and aggregator if you need the info with specific driver reference id by using get() and map() functions.

Regards,
Msquare Automation - Gold Partner of Make
@Msquare_Automation

Maybe my inexperience is showing. When I tried using the Map/ Get combination, it did not return the entire complex structure which is not what I wanted. Also, would I actually save 2 operations? Doesn’t using Map/Get use an operation?

1 Like

You will need to use get() and map() function while mapping in your next module.

For example:

{{get(map(array_here;value_needed_to_map;driver.id;20134);1}}

These are functions, functions doesn’t cost any operation.

Regards,
Msquare Automation - Gold Partner of Make
@Msquare_Automation

Before I published my solution, I tried to use get/map, but could not get the result I’m looking for. If you don’t mind, let’s walk through it. The main array is called bookings() and under that array, there are a number of collections - one of which is called Driver and one of the elements in the driver collection is the driver Ref which is the value I have to filter by.
The array has so many elements in it, including many collections, that I can’t even create one screen print to contain it. So here is one screen print that has the beginning of the bookings array:


As you can see, we have the beginning of the array and lots of elements that are at the top level of the array. Here we have a screen print taken by scrolling down from the screen print above:

As you can see, there are many collections of data within the booking array.

My goal is to get the whole entire array in my solution. You have suggested that I use map/get in this way: {{get(map(array_here;value_needed_to_map;driver.id;20134);1}}
I put in my data and it looks like this: {{get(map(3.data.body.bookings; “driver”; “driver.ref”; 2701234); 1)}}
The result is just the driver collection - not the full array of related data. I’ve tried substituting various things (e.g. bookings or bookings.driver) for the ‘value_needed_to_map’ but it produces an empty result. Obviously, I’m missing something about how to use get/map on such a complex data structure.

And, to push on the # of operations question once more… a function itself doesn’t use any operations, but whatever module you use (usually a variable module, right?) with the function inside of it will use an operation. Once I get the data I want, the resulting array goes through another filter to evaluate additional attributes to determine if the next steps of the program should be executed or not - so I would have to use a module with the function inside of it before filtering for other values - right?