Find the same value in arrays of different records (array of items containing any value in another array of items)

Hi Make community,

I try to compare multiple arrays (from 2 different records) with each other. The comparison is successful if the compared arrays have one or more of the same values.

Consider the following scenario:
We have Contact Type A (Provider) with the following arrays:
Vertical: Blue, Red, Green
Size: M, L

And we have 4 records of Contact Type B (Requester), each with the following arrays:
Requester #1
Vertical: Red
Size: L

Requester #2
Vertical: Blue, Yellow
Size: M, XL

Requester #3
Vertical: Purple, Black
Size: M

Requester #4
Vertical: Purple, Black
Size: XL, XXL

Desired result:
Only the contacts Requester #1 and Requester #2 successfully pass the conditions because each has at least one overlapping value in each array with Contact Type A (Provider).

Requester #3 doesn’t have the correct vertical (besides having the correct size), and Requester 4 has no overlapping values. Both values are not moving forward in the scenario.

I created the following “Iterator Chain” (see below) in the scenario, which works, but it feels like a very inefficient way of building a scenario and a waste of actions (= money). In the chain, each array is compared after the other, and only filtered records move forward to the next “array comparison.” Imagine that with 20 different arrays and 100s of requesters, and you get an idea why it will quickly waste a lot of actions.

My goal is to have one step in which all arrays are compared at the same time. Does anyone have an idea of how to achieve this? Thanks to everyone who is looking into this problem with me.

Welcome to the Make community!

Do you have some example output bundles for the Iterator module?

Please provide the output bundles of the Iterator module by running the scenario (or get from the scenario History tab), then click the white speech bubble on the top-right of each module and select “Download input/output bundles”.
Screenshot_2023-10-06_141025

A.

Save each bundle contents in your text editor as a bundle.txt file, and upload it here into this discussion thread.

Uploading them here will look like this:

module-1-input-bundle.txt (12.3 KB)
module-1-output-bundle.txt (12.3 KB)

B.

If you are unable to upload files on this forum, alternatively you can paste the formatted bundles 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 input/output bundles will allow others to replicate what is going on in the scenario even if they do not use the external service.

This will allow others to better assist you. Thanks!

samliew – request private consultation

Join the unofficial Make Discord server to chat with other makers!

3 Likes

Hi Sam,

Thank you a lot for the kind welcome. Please find below the input and output bundles for the operations.

1- Lookup Provider Output.txt (518 Bytes)
2- Lookup Requester Output.txt (2.3 KB)
3- Aggregator Input.txt (1017 Bytes)
3- Aggregator Output.txt (1.4 KB)
4- Iterator Output.txt (1.2 KB)

Thank you a lot for looking into this!!

You already have all the modules required to perform the filtering.

Namely, the “Lookup Provider Output” and “Iterator Output” (where you iterated the Requesters).

You do NOT need to Iterate the Vertical and do NOT need to Iterate the Size (as shown in your first two screenshots in this thread).

You might not even need the aggregator/iterator, because this combination converts bundles into an array, then an array back into bundles.

All you need now is a filter with two patterns:

Output:

samliew – request private consultation

Join the unofficial Make Discord server to chat with other makers!

3 Likes

Module Export

You can copy and paste this module export into your scenario. This will paste the modules shown in my screenshots above.

  1. Copy the JSON code below by clicking the copy button when you mouseover the top-right of the code block
    Screenshot_2024-01-17_200117

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the canvas.

  3. Click on each imported module and save it for validation. You may be prompted to remap some variables and connections.

View Module Export Code

JSON

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 29,
                    "module": "json:ParseJSON",
                    "version": 1,
                    "parameters": {
                        "type": ""
                    },
                    "mapper": {
                        "json": "[\n    {\n        \"Vertical\": [\n            \"Blue\",\n            \"Green\",\n            \"Red\"\n        ],\n        \"Email\": \"provider@email.com\",\n        \"Category\": \"Provider\",\n        \"First name\": \"Test\",\n        \"Investment Thesis\": [\n            \"recbbYvTrRsFlHc0Y\"\n        ],\n        \"Last name\": \"Provider\",\n        \"Message name\": \"Test\",\n        \"Full name\": \"Test Provider\",\n        \"Size\": [\n            \"M\",\n            \"L\"\n        ],\n        \"id\": \"XXX\",\n        \"createdTime\": \"2024-05-10T18:36:52.000Z\"\n    }\n]"
                    },
                    "metadata": {
                        "designer": {
                            "x": -637,
                            "y": -1417,
                            "name": "1. Lookup Provider Output"
                        },
                        "restore": {
                            "parameters": {
                                "type": {
                                    "label": "Choose a data structure"
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "type",
                                "type": "udt",
                                "label": "Data structure"
                            }
                        ],
                        "expect": [
                            {
                                "name": "json",
                                "type": "text",
                                "label": "JSON string",
                                "required": true
                            }
                        ]
                    }
                },
                {
                    "id": 30,
                    "module": "json:ParseJSON",
                    "version": 1,
                    "parameters": {
                        "type": ""
                    },
                    "mapper": {
                        "json": "[\n    {\n        \"Size\": [\n            \"L\"\n        ],\n        \"Email\": \"requester1@email.com\",\n        \"Category\": \"Requester\",\n        \"Vertical\": [\n            \"Red\"\n        ],\n        \"Full name\": \"Test YES Requester 1\",\n        \"__IMTINDEX__\": 1,\n        \"__IMTLENGTH__\": 4\n    },\n    {\n        \"Size\": [\n            \"M\",\n            \"XL\"\n        ],\n        \"Email\": \"requester2@email.com\",\n        \"Category\": \"Requester\",\n        \"Vertical\": [\n            \"Blue\",\n            \"Yellow\"\n        ],\n        \"Full name\": \"Test YES Requester 2\",\n        \"__IMTINDEX__\": 2,\n        \"__IMTLENGTH__\": 4\n    },\n    {\n        \"Size\": [\n            \"M\"\n        ],\n        \"Email\": \"requester3@email.com\",\n        \"Category\": \"Requester\",\n        \"Vertical\": [\n            \"Purple\",\n            \"Black\"\n        ],\n        \"Full name\": \"Test No Requester 3\",\n        \"__IMTINDEX__\": 3,\n        \"__IMTLENGTH__\": 4\n    },\n    {\n        \"Size\": [\n            \"XL\",\n            \"XXL\"\n        ],\n        \"Email\": \"requester4@email.com\",\n        \"Category\": \"Requester\",\n        \"Vertical\": [\n            \"Purple\",\n            \"Black\"\n        ],\n        \"Full name\": \"Test No Requester 4\",\n        \"__IMTINDEX__\": 4,\n        \"__IMTLENGTH__\": 4\n    }\n]"
                    },
                    "metadata": {
                        "designer": {
                            "x": -421,
                            "y": -1378,
                            "name": "4. Iterator Output"
                        },
                        "restore": {
                            "parameters": {
                                "type": {
                                    "label": "Choose a data structure"
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "type",
                                "type": "udt",
                                "label": "Data structure"
                            }
                        ],
                        "expect": [
                            {
                                "name": "json",
                                "type": "text",
                                "label": "JSON string",
                                "required": true
                            }
                        ]
                    }
                },
                {
                    "id": 32,
                    "module": "util:SetVariables",
                    "version": 1,
                    "parameters": {},
                    "filter": {
                        "name": "conditions",
                        "conditions": [
                            [
                                {
                                    "a": "{{join(29.Size; \"|\")}}",
                                    "o": "text:pattern:ci",
                                    "b": "\\b({{join(30.Size; \"|\")}})\\b"
                                },
                                {
                                    "a": "{{join(29.Vertical; \"|\")}}",
                                    "o": "text:pattern:ci",
                                    "b": "\\b({{join(30.Vertical; \"|\")}})\\b"
                                }
                            ]
                        ]
                    },
                    "mapper": {
                        "variables": [
                            {
                                "name": "requester_name",
                                "value": "{{30.`Full name`}}"
                            },
                            {
                                "name": "requester_size",
                                "value": "{{30.Size}}"
                            },
                            {
                                "name": "requester_vertical",
                                "value": "{{30.Vertical}}"
                            }
                        ],
                        "scope": "roundtrip"
                    },
                    "metadata": {
                        "designer": {
                            "x": -128,
                            "y": -1378
                        },
                        "restore": {
                            "expect": {
                                "variables": {
                                    "items": [
                                        null,
                                        null,
                                        null
                                    ]
                                },
                                "scope": {
                                    "label": "One cycle"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "variables",
                                "type": "array",
                                "label": "Variables",
                                "spec": [
                                    {
                                        "name": "name",
                                        "label": "Variable name",
                                        "type": "text",
                                        "required": true
                                    },
                                    {
                                        "name": "value",
                                        "label": "Variable value",
                                        "type": "any"
                                    }
                                ]
                            },
                            {
                                "name": "scope",
                                "type": "select",
                                "label": "Variable lifetime",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        "roundtrip",
                                        "execution"
                                    ]
                                }
                            }
                        ],
                        "interface": [
                            {
                                "name": "requester_name",
                                "label": "requester_name",
                                "type": "any"
                            },
                            {
                                "name": "requester_size",
                                "label": "requester_size",
                                "type": "any"
                            },
                            {
                                "name": "requester_vertical",
                                "label": "requester_vertical",
                                "type": "any"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}
2 Likes

You are an absolute genius @samliew

It works, I can’t believe it. Ultimately, I didn’t even need an aggregator or iterator and immediately added the filter after the “lookup requester” module. Also, I removed the \b that you added to your formula. I am not sure why you added that, but it works also without it. Please see below the total workflow and the formulas.

Again, thank you so much for your help!! Still can’t believe that it works now.



You should not remove the \b – this ensures a complete match.

E.g.: 1 matches 1 exactly and not 123 (which also contains a 1)

2 Likes

Ah, I understand! Thank you a lot. I will add it again.

1 Like