Hello
I'm experiencing a strange behaviour when reading an array from the context store.
The array is altered in the context store just by reading it inside the function block.
Please can someone explain to me why this is happening.
I include a example flow:
[
{
"id": "aacefb7f.a06e28",
"type": "inject",
"z": "ab2e2a9e.27b058",
"name": "Set Global var",
"topic": "",
"payload": "[{\"DowntimeCode\":\"DT009\",\"DownTimeL1\":\"OEE\",\"DownTimeL2\":\"Unplanned Stoppage\",\"DownTimeL3\":\"Parts Contaminated with Swarf\",\"DownTimeL4\":\"Parts Contaminated with Swarf\",\"AccessLevel\":\"1 \",\"Filter\":\"ALL\",\"Valid\":\"Y\",\"Rank\":1},{\"DowntimeCode\":\"DT038\",\"DownTimeL1\":\"OEE\",\"DownTimeL2\":\"Unplanned Stoppage\",\"DownTimeL3\":\"Part Jammed in the Feed Rail\",\"DownTimeL4\":\"Part Jammed in the Feed Rail\",\"AccessLevel\":\"1 \",\"Filter\":\"ALL\",\"Valid\":\"Y\",\"Rank\":2},{\"DowntimeCode\":\"DT039\",\"DownTimeL1\":\"OEE\",\"DownTimeL2\":\"Production rate Deviation\",\"DownTimeL3\":\"Mixed Parts\",\"DownTimeL4\":\"Mixed Parts\",\"AccessLevel\":\"1 \",\"Filter\":\"ALL\",\"Valid\":\"Y\",\"Rank\":2}]",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 210,
"y": 520,
"wires": [
[
"78d1f8f.b1c8308"
]
]
},
{
"id": "78d1f8f.b1c8308",
"type": "change",
"z": "ab2e2a9e.27b058",
"name": "",
"rules": [
{
"t": "set",
"p": "dtcodeLV1",
"pt": "global",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 420,
"y": 520,
"wires": [
[]
]
},
{
"id": "1cd8e8a0.25c0f7",
"type": "inject",
"z": "ab2e2a9e.27b058",
"name": "Read Global var (this will break it)",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 270,
"y": 580,
"wires": [
[
"f4fb9963.0ef488"
]
]
},
{
"id": "59a2ab43.265574",
"type": "debug",
"z": "ab2e2a9e.27b058",
"name": "Altered Array in context store",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 840,
"y": 580,
"wires": []
},
{
"id": "f4fb9963.0ef488",
"type": "function",
"z": "ab2e2a9e.27b058",
"name": "read array from context store",
"func": "var arr = global.get('dtcodeLV1');\nreturn arr;",
"outputs": 1,
"noerr": 0,
"x": 560,
"y": 580,
"wires": [
[
"59a2ab43.265574"
]
]
},
{
"id": "bf6be241.7ad6",
"type": "inject",
"z": "ab2e2a9e.27b058",
"name": "Read Global var (this works fine)",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 270,
"y": 700,
"wires": [
[
"a2cb83fc.c62ef"
]
]
},
{
"id": "a2cb83fc.c62ef",
"type": "change",
"z": "ab2e2a9e.27b058",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "dtcodeLV1",
"tot": "global"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 540,
"y": 700,
"wires": [
[
"dcad5382.3dcc3"
]
]
},
{
"id": "dcad5382.3dcc3",
"type": "debug",
"z": "ab2e2a9e.27b058",
"name": "Unchanged array context store",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 850,
"y": 700,
"wires": []
},
{
"id": "9dfed747.32b628",
"type": "inject",
"z": "ab2e2a9e.27b058",
"name": "Read Global var (this works fine)",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 270,
"y": 640,
"wires": [
[
"537f7bd7.685914"
]
]
},
{
"id": "25dc1cc6.ce4b04",
"type": "debug",
"z": "ab2e2a9e.27b058",
"name": "Unchanged array in context store",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 860,
"y": 640,
"wires": []
},
{
"id": "537f7bd7.685914",
"type": "function",
"z": "ab2e2a9e.27b058",
"name": "read array from context store",
"func": "var arr = global.get('dtcodeLV1');\nmsg.payload = arr;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 540,
"y": 640,
"wires": [
[
"25dc1cc6.ce4b04"
]
]
}
]