How do I get the text object from this iterator?

I am trying to get a text that reads “North America & East Asia” by iterating through a collection that has each string and text aggregating them with an “Other” row seperator, which is “&”

This is the setup
image

here is the run from the iterator, so far so good.
image

Here is how I setup the Text Aggregator.

I have tried both {{85.value}} and {{85.value.text}}

But I get Empty for everything that I try.
image

Try

{{85.text}}

But why do you need an iterator just to join it back together with a Text Aggregator?

I think you should be able to use the built-in functions map and join so you can save two operations.

3 Likes

Yeah, since your input to the iterator is already an array just feed that array into the Text Aggregator which specifically is meant to combine array data into a specified data format.

3 Likes

Thanks.
{{85.text}} does indeed work here.

I’m using the iteratior to get the “&” in between if I have more than 1 Region.
Is there a function that is not overly complex that gets to the same result?

No. You need to iterate and aggregate. You could I suppose do some tricky set variable but why? This is the right way to do it.

2 Likes

Thanks for the input!
Much appreciated!

Screenshot_2024-04-19_230458

Screenshot_2024-04-19_230406

3 Likes

Impressive! Thx Samliew

If there is only 1 item in the array you will end up with a trailing space & space. So you’d need to do an if() to evaluate the length of the array first and conditionally not add a & for when length(10.Array) = 1.

Most commonly I have 1 item in this Array.

No, that’s not how join works.

If there is only a single item in the array, nothing is “joined” with the separator.

So the output will be the single item in the array.

Screenshot_2024-04-20_100422

Feel free to test it yourself, I’ll leave the module export below:

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": 10,
                    "module": "json:ParseJSON",
                    "version": 1,
                    "parameters": {
                        "type": ""
                    },
                    "mapper": {
                        "json": "{\"Array\": [\n{\n  \"dropdownOptionId\": 1234567, \n  \"text\": \"North America\"\n}\n,{\n  \"dropdownOptionId\": 9876543, \n  \"text\": \"East Asia\"\n}\n]}"
                    },
                    "metadata": {
                        "designer": {
                            "x": -9,
                            "y": -858,
                            "name": "An array of collections"
                        },
                        "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": 11,
                    "module": "util:SetVariable2",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "name": "Output",
                        "scope": "roundtrip",
                        "value": "{{join(map(10.Array; \"text\"); space + \"&\" + space)}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 293,
                            "y": -858,
                            "name": "Join array with mapped property"
                        },
                        "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": "Output",
                                "type": "any",
                                "label": "Output"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}

Run it once, observe the output.

Delete the second item in the array, and run it again.

Screenshot_2024-04-20_100447

2 Likes

Cool I didn’t know that but now I do. Thanks for the explanation!

2 Likes