Find max value in array of ints

I created the blueprint below to try and find the maximum value in an array of numbers, but I can’t figure out how to update a variable’s value.
Specifically, in the 2nd iteration, the value of max is -1 instead of 3.
How can I do so?

Thanks.

{
    "name": "test2",
    "flow": [
        {
            "id": 6,
            "module": "util:SetVariable2",
            "version": 1,
            "parameters": {},
            "mapper": {
                "name": "max",
                "scope": "execution",
                "value": "-1"
            },
            "metadata": {
                "designer": {
                    "x": 296,
                    "y": 15
                },
                "restore": {
                    "expect": {
                        "scope": {
                            "label": "One execution"
                        }
                    }
                },
                "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": "max",
                        "type": "any",
                        "label": "max"
                    }
                ],
                "advanced": true
            }
        },
        {
            "id": 7,
            "module": "builtin:BasicFeeder",
            "version": 1,
            "parameters": {},
            "mapper": {
                "array": [
                    "3",
                    "2"
                ]
            },
            "metadata": {
                "designer": {
                    "x": 687,
                    "y": 11
                },
                "restore": {
                    "expect": {
                        "array": {
                            "mode": "chose",
                            "items": [
                                null,
                                null
                            ]
                        }
                    }
                },
                "expect": [
                    {
                        "mode": "edit",
                        "name": "array",
                        "spec": [],
                        "type": "array",
                        "label": "Array"
                    }
                ]
            }
        },
        {
            "id": 8,
            "module": "util:SetVariable2",
            "version": 1,
            "parameters": {},
            "mapper": {
                "name": "max",
                "scope": "execution",
                "value": "{{if(6.max <= 7.value; 7.value; 6.max)}}"
            },
            "metadata": {
                "designer": {
                    "x": 1056,
                    "y": 19
                },
                "restore": {
                    "expect": {
                        "scope": {
                            "label": "One execution"
                        }
                    }
                },
                "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": "max",
                        "type": "any",
                        "label": "max"
                    }
                ],
                "advanced": true
            }
        },
        {
            "id": 9,
            "module": "builtin:BasicAggregator",
            "version": 1,
            "parameters": {
                "feeder": 7
            },
            "mapper": {},
            "metadata": {
                "designer": {
                    "x": 1428,
                    "y": 16
                },
                "restore": {
                    "extra": {
                        "feeder": {
                            "label": "Iterator [7]"
                        },
                        "target": {
                            "label": "Custom"
                        }
                    }
                }
            }
        },
        {
            "id": 10,
            "module": "util:GetVariable2",
            "version": 1,
            "parameters": {},
            "mapper": {
                "name": "max"
            },
            "metadata": {
                "designer": {
                    "x": 1871,
                    "y": 13
                },
                "restore": {},
                "expect": [
                    {
                        "name": "name",
                        "type": "text",
                        "label": "Variable name",
                        "required": true
                    }
                ],
                "interface": [
                    {
                        "name": "max",
                        "type": "any",
                        "label": "max"
                    }
                ]
            }
        }
    ],
    "metadata": {
        "instant": false,
        "version": 1,
        "scenario": {
            "roundtrips": 1,
            "maxErrors": 3,
            "autoCommit": true,
            "autoCommitTriggerLast": true,
            "sequential": false,
            "slots": null,
            "confidential": false,
            "dataloss": false,
            "dlq": false,
            "freshVariables": false
        },
        "designer": {
            "orphans": []
        },
        "zone": "eu2.make.com"
    }
}

Hey @tal
welcome to the make community

You can use Numeric aggregator
image

You do not need so many modules.

Here’s an additional screenshot to show output of the Numeric Aggregator, as suggested by Manish:

You can also use the built-in function max

Screenshot_2024-07-05_110752

For more information, see the function documentation in the Help Center.

samliew – request private consultation

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