Hello Make Community!
I’ve been beating a dead horse and cannot think of any other way to possibly filter the array appropriately and I presume other members may have this issue.
Here’s the scenario, after preforming any type of action that gathers an array of collections. I’m attempting to filter based if a string value is within the values of the collection.
When asking your question, please include:
The steps you have taken
- Using the built-in filter method using the Array contains feature.
1a. Returns false every time, even in one of the collections within the array has said string
- Using the built in method contains with the map method wrapped inside.
Looks like this: contains(map(array_of_collections; array_of_collections.key (this is the known key that the target_string would be associated with); target_string; target_string)
2a. Return false every time
- Convert the array object to string and parse using RegEx.
Built-in method toString(array_of_collections)
Now this is where things get very peculiar, as the toString method does not convert the object to a string. Instead, the method coverts the array of collections to an array of objects.
Here is the result of the switch case using the toString method embedded.
And this shows the originating array of collections.
Hi there, @BordenC!
If you just want to check if the “name” variable contains one of those values, I would suggest using the map function like this: map(Array;name) and then passing this in a filter with the Array: contains case insensitive operator. I’ve attached a simple blueprint that you can import to see it in action.
blueprint (6).json (4.2 KB)
Hope it helps!
Thanks @Bruno_T for the quick reply,
Worked in once instance, but does not work in a different instance.
This is the filter I am using, similar issue, an array of collections (whose size can be >1)
This is the array of collections I’m filtering on.
The first screenshot, we are looking to parse for the name from another module, the module’s value was “Eric”. The second screenshot is the array being filtered. Whose only collection has the value of “Eric”
Ah, that’s because Eric has a surname and you’re trying to match the whole name to the first name only. “Eric Surname” =/= “Eric”.
In that case I would recommend that after map you use join to convert the array to a string and then use the Text contains operator instead of the array operator. Something like this:
Oh I understand, and agree. I thought there was partial matching.
It’d be neat to be able to do RegEx functions inside the filter conditioning!
Oh, that would be awesome!
I found this feature request that you can upvote as well so maybe we will see this in the future.
For now, I have a hacky workaround:
The replace function works with RegEx, so you can use it to replace the expression you’re looking for with an emptystring for example, and then compare the length of the result to the original string. If it’s different, you’ll know you matched and replaced something!
Here my input was aaaaab13aaaaa. Since the RegEx matches b13 and replaces it with nothing (emptystring) the length of the result is 10 while the original length is 13.
I hope this comes in handy!