Unwanted circular update of variables

I'm creating a new array from a global array and for a reason I cannot understand the global array gets updated on the same time as the new one, see example.

For info, I'm using ContextStorage to 'memory' as default and optionally to 'file', the circular issue occurs for both types of storage.

[
    {
        "id": "6dd670b22423b177",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "c18f55a1a1dc87e4",
        "type": "inject",
        "z": "6dd670b22423b177",
        "name": "add 15 min",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "00 17 * * *",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 130,
        "y": 220,
        "wires": [
            [
                "73e3f0e04dd115c8"
            ]
        ]
    },
    {
        "id": "73e3f0e04dd115c8",
        "type": "function",
        "z": "6dd670b22423b177",
        "name": "+15 min",
        "func": "var dd = global.get(\"ccc\");\ndd.minute = dd.minute + 15\n\nif (dd.minute > 59) {\n    dd.minute = dd.minute - 60\n    dd.hour = dd.hour + 1\n}\n\nflow.set(\"ddd\", dd, \"file\");\n\nreturn null;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 280,
        "y": 220,
        "wires": [
            []
        ]
    },
    {
        "id": "68da3984b80c8313",
        "type": "inject",
        "z": "6dd670b22423b177",
        "name": "set time",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "30 04 * * *",
        "once": false,
        "onceDelay": "0.5",
        "topic": "",
        "payload": "true",
        "payloadType": "bool",
        "x": 120,
        "y": 180,
        "wires": [
            [
                "d57ef3b9af0306be"
            ]
        ]
    },
    {
        "id": "d57ef3b9af0306be",
        "type": "function",
        "z": "6dd670b22423b177",
        "name": "Save times",
        "func": "var cc = { minute: 0, hour: 19 };\nglobal.set(\"ccc\", cc);",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 290,
        "y": 180,
        "wires": [
            []
        ]
    }
]

This comes up regularly, most recently a few hours ago. A lot can be learned by watching the forum and trying to at least read all the questions, and following any threads that look interesting.

Ok, thanks. I did a search but probably not with the good search words (beginners error to define the problem)

It is often difficult to search for related issues when you are not really sure what the issue is :slight_smile:

2 Likes

RED.util.cloneMessage() worked like a charm. Thanks

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.