Hello everyone, I am new with nodeRed and need your help. I have a flow where I get the array of objects using a filter node, but when a new object comes then previous objects also shows in the array. I only want to show latest or newly added object and ignore other objects in the array.
Please also help me, how I can use "change node" for that. Small piece of code based on this flow will be really nice. Thanks.
For testing purpose, You can use the given flow.
[
{
"id": "c0db56cb5bb57a0c",
"type": "debug",
"z": "3b03cefb5969952e",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1310,
"y": 220,
"wires": []
},
{
"id": "993ea01743adb656",
"type": "function",
"z": "3b03cefb5969952e",
"name": "",
"func": "msg.method = \"POST\"\nmsg.headers = {'Accept': 'application/json'}\n\nvar dataLoad = msg.payload;\nflow.set(\"dataLoad\", dataLoad);\n\nvar len = dataLoad.length;\n\nlastCreatedDate = msg.payload[0].createdAt;\n\nmsg.lastCreatedDate = lastCreatedDate;\n\nfor (i=0; i<len; i++)\n{\n msg.payload[i]={\n \"fields\": {\n \"Unique Nethunt ID Organization\": msg.payload[i].id,\n \"Name\": msg.payload[i].fields.Name,\n \"Link to Nethunt\": msg.payload[i].link,\n \"Billing Address\": msg.payload[i].fields[\"Billing Address\"],\n \"tags\": msg.payload[i].fields.Branch\n }\n }\n}\n\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 940,
"y": 220,
"wires": [
[
"3d44e20151b739bd"
]
]
},
{
"id": "91cb042cc680373a",
"type": "inject",
"z": "3b03cefb5969952e",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "[{\"id\":\"6316f3473d2c5949262f33b3\",\"recordId\":\"6316f3473d2c5949262f33b3\",\"createdAt\":\"2022-09-06T07:14:15.460Z\",\"fields\":{\"Name\":\"Test name\",\"Billing Address\":\"address test\",\"Country\":\"DE\",\"Contact Source\":\"Kontaktformular\",\"Responsible\":[\"fd@mailing.de\"],\"Category\":[\"Kunden\"],\"Processing Status\":\"in Bearbeitung\",\"Branch\":[\"Heizung und Sanitär\"],\"Business Purpose\":[\"Handwerk\"],\"Products\":[\"6' Lagercontainer\",\"8' Lagercontainer\"],\"Record generated by\":\"Created manually\"},\"link\":\"https://nethunt.com/web/#nethunt\"},{\"id\":\"6315ef4c6aa8992f5209bfbe1\",\"recordId\":\"6315ef4c6aa8992f5209bfbe1\",\"fields\":{\"Name\":\"Test name 1\",\"Billing Address\":\"address test 1\",\"Country\":\"DE\",\"Contact Source\":\"Kontaktformular 1\",\"Responsible\":[\"fd@mailing.de\"],\"Category\":[\"Kunden\"],\"Processing Status\":\"in Bearbeitung 1\",\"Branch\":[\"Heizung und Sanitär 1\"],\"Business Purpose\":[\"Handwerk 1\"],\"Products\":[\"6' Lagercontainer 1\",\"8' Lagercontainer 1\"],\"Record generated by\":\"Created manually 1\"},\"link\":\"https://nethunt.com/web/#nethunt 1\"}]",
"payloadType": "json",
"x": 790,
"y": 180,
"wires": [
[
"993ea01743adb656"
]
]
},
{
"id": "3d44e20151b739bd",
"type": "rbe",
"z": "3b03cefb5969952e",
"name": "",
"func": "rbe",
"gap": "",
"start": "",
"inout": "out",
"septopics": true,
"property": "payload",
"topi": "topic",
"x": 1110,
"y": 220,
"wires": [
[
"c0db56cb5bb57a0c"
]
]
},
{
"id": "8f690cdbe9d19147",
"type": "inject",
"z": "3b03cefb5969952e",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "[{\"id\":\"6316ff796aa8992f520ad92b\",\"recordId\":\"6316ff796aa8992f520ad92b\",\"createdAt\":\"2022-09-06T08:06:17.761Z\",\"fields\":{\"Name\":\"Test name 0\",\"Billing Address\":\"test address 0\",\"Country\":\"DE\",\"Contact Source\":\"Kontaktformular 0\",\"Responsible\":[\"fd@mailing.de\"],\"Category\":[\"Kunden\"],\"Processing Status\":\"in Bearbeitung 0\",\"Branch\":[\"Metall- und Stahlbau\"],\"Business Purpose\":[\"Herstellung\"],\"Products\":[\"40' HC 000\"],\"Record generated by\":\"Created manually 0\"},\"link\":\"https://nethunt.com/web/#nethunt/\"},{\"id\":\"6316f3473d2c5949262f33b3\",\"recordId\":\"6316f3473d2c5949262f33b3\",\"createdAt\":\"2022-09-06T07:14:15.460Z\",\"fields\":{\"Name\":\"Test name\",\"Billing Address\":\"address test\",\"Country\":\"DE\",\"Contact Source\":\"Kontaktformular\",\"Responsible\":[\"fd@mailing.de\"],\"Category\":[\"Kunden\"],\"Processing Status\":\"in Bearbeitung\",\"Branch\":[\"40' HC 001\"],\"Business Purpose\":[\"Handwerk\"],\"Products\":[\"6' 40' HC 001\",\"8' 40' HC 001\"],\"Record generated by\":\"Created manually\"},\"link\":\"https://nethunt.com/web/#nethunt\"},{\"id\":\"6315ef4c6aa8992f5209bfbe1\",\"recordId\":\"6315ef4c6aa8992f5209bfbe1\",\"createdAt\":\"2022-09-06T07:14:15.460Z\",\"fields\":{\"Name\":\"Test name 1\",\"Billing Address\":\"address test 1\",\"Country\":\"DE\",\"Contact Source\":\"Kontaktformular 1\",\"Responsible\":[\"fd@mailing.de\"],\"Category\":[\"Kunden\"],\"Processing Status\":\"in Bearbeitung 1\",\"Branch\":[\"Heizung und Sanitär 1\"],\"Business Purpose\":[\"Handwerk 1\"],\"Products\":[\"6' 40' HC 002\",\"8' 40' HC 002\"],\"Record generated by\":\"Created manually 1\"},\"link\":\"https://nethunt.com/web/#nethunt 1\"}]",
"payloadType": "json",
"x": 790,
"y": 240,
"wires": [
[
"993ea01743adb656"
]
]
}
]