Mapping Arrays nested collections

Hi there Makers, :man_dancing:

I know its probably a frequntly asked question… im trying to figure out how to get the Email address where the Function=Support or Finance, basically I need to map both out of Aggregator.

When I use the Map function as below im not getting any results, I assume its becasue its nested in collections.
image

Any staight forward suggestions how to get the relevant email addresses from the Collections within the Arrays?

Hi @OmriNyx,

You need use an addition map function to first to map the “Record” before map to get just the email.

Using the payload you have returned from your array. I have created a test set.

Then from this I used your variable “Support Email” to then create this formula to bring back support emails

{{get(map(map(16.array; “Record”); “Email”; “Function”; “Support”); 1)}}

From this the support email brought back should be “test1@test.com

image

Let me know if this works!

2 Likes

Raw keys in the map function

Are you certain you are mapping the RAW key?

e.g.: function instead of Function ?

e.g.: record instead of Record ?

Then,

You should only need one map function:

{{ first(map(16.array; "Record.Email"; "Record.Function"; "Support")) }}

Screenshot_2024-04-25_170422

(replace the above keys with the actual raw key, not the label as shown in the output bundle)

Demo

Screenshot_2024-04-25_170411

Screenshot_2024-04-25_170430

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.

JSON

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 72,
                    "module": "json:ParseJSON",
                    "version": 1,
                    "parameters": {
                        "type": ""
                    },
                    "mapper": {
                        "json": "{\"Array\": [\n  {\n    \"Record\": {\n\"Function\": \"Support\",\n\"Email\": \"support@company.com\"\n    }\n  },\n  {\n    \"Record\": {\n\"Function\": \"Finance\",\n\"Email\": \"finance@company.com\"\n    }\n  }\n]}"
                    },
                    "metadata": {
                        "designer": {
                            "x": -931,
                            "y": -2441
                        },
                        "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": 73,
                    "module": "util:SetVariable2",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "name": "Support Email",
                        "scope": "roundtrip",
                        "value": "{{first(map(72.Array; \"Record.Email\"; \"Record.Function\"; \"Support\"))}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": -687,
                            "y": -2444
                        },
                        "restore": {
                            "expect": {
                                "scope": {
                                    "label": "One cycle"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "name",
                                "type": "text",
                                "label": "Variable name",
                                "required": true
                            },
                            {
                                "name": "scope",
                                "type": "select",
                                "label": "Variable lifetime",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        "roundtrip",
                                        "execution"
                                    ]
                                }
                            },
                            {
                                "name": "value",
                                "type": "any",
                                "label": "Variable value"
                            }
                        ],
                        "interface": [
                            {
                                "name": "Support Email",
                                "label": "Support Email",
                                "type": "any"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}
4 Likes

Hi @David_Dallyn This could be a good idea, and I might use it in future automations. I appreciate your quick reply

@samliew Idea was a bit more straight forward and I have managed to solve the issue based on his 2 main pointers:

  1. I rechecked the raw data and realized that “Record” actually appears as “data” in the code

Blockquote[
{
“array”: [
{
“data”: {
“Company Name”: “Test Partner”,
“Partner Code”: “666 TST”,
“Country”: “USA”,
“Function”: “Finance”,
“Email”: “finance@email.com
}
},
{
“data”: {
“Company Name”: “Test Partner”,
“Partner Code”: “666 TST”,
“Country”: “USA”,
“Function”: “Support”,
“Email”: “support@email.com
}
}
],
IMTAGGLENGTH”: 2
}
]

  1. That it was easy to “sub-map” the fields using data.Email and data.Function so no extra mapping is needed :blush:

Thank you both very much !

2 Likes