How to check if collection contains string?

I’ve always been confused about this…

Here, there will only be Bundle 1.
Within it, Invoice Items may contain 0 or multiple items.

Need:

I want a downstream action to happen only if there is not already an Invoice item whose “Description” contains a given phrase. (In other words, I want to avoid adding a duplicate invoice item).

I want to avoid running a real check on every item in Invoice Items, to keep usage down.

Tried:

Tried an Iterator and Array Aggregator to get an array of "Description"s.
Then tried a range of filters on that. But I can never seen to get it to work.

If I can answer “How do I check an array for matching text?”, I think it would be a useful skill added to the list.

I might have stumbled upon a solution in the filter…

  • Get the invoice (see first post for output).
  • Iterator to only get the Invoice Items[] part.
  • Array Aggregator to reassemble with only Description fields.
  • Filter the description fields using {{map(46.array; "description")}} and a Contains Text Operator, not the Array-specific Contains filter.

It seems to work.
Does anyone care to explain how, or if I may have anything that’s superfluous?

I presume the map filter, this way, won’t be incurring multiple runs.

Credit Filtering Issues on an array of collections - #2 by Bruno_T with helping.

3 Likes

Welcome to the Make community!

Please provide the output bundles of the modules by running the scenario, then click the white speech bubble on the top-right of each module and select “Download output bundles”.
Screenshot_2023-10-06_141025

A.

Save the bundle contents in your text editor as a bundle.txt file, and upload it here into this discussion thread.
Uploading it here will look like this:

bundle.txt (12.3 KB)

B.

If you are unable to upload files on this forum, alternatively you can paste the formatted output bundle in this manner:

  • Either add three backticks ``` before and after the code, like this:

    ```
    input/output bundle content goes here
    ```

  • Or use the format code button in the editor:
    Screenshot_2023-10-02_191027

Providing the output bundles will allow others to replicate what is going on in the scenario even if they do not use the external service.

The output bundles are necessary since screenshots do not show “raw” key values – only their labels.

This will allow others to better assist you. Thanks!

2 Likes

Make support explains:

In general, the map function makes a simple array of values from a complex array. (https://www.make.com/en/help/functions/array-functions#map-complex-array--key--key-for-filtering---possible-values-for-filtering-separated-by-a-comma--) So, in the context of your scenario, the map function in the filter should provide you with the simple array of descriptions.

That’s quite a useful way of describing something I never quite understood.

2 Likes