Flow:
[
{
"id": "1c81edcb527606e1",
"type": "inject",
"z": "1151076dd0552f2d",
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "[{\"status\":\"DELIVERED\",\"dateIso\":\"2023-03-03T10:26:00+01:00\"},{\"status\":\"HANDED_IN\",\"dateIso\":\"2023-02-24T14:10:50+01:00\"},{\"status\":\"DELIVERED\",\"dateIso\":\"2023-01-26T12:42:50+01:00\"},{\"status\":\"IN_TRANSIT\",\"dateIso\":\"2023-01-23T19:28:08+01:00\"},{\"status\":\"PRE_NOTIFIED\",\"dateIso\":\"2023-01-19T09:01:08+01:00\"}]",
"payloadType": "json",
"x": 1010,
"y": 1260,
"wires": [
[
"6660c65d96d28d5c"
]
]
},
{
"id": "6660c65d96d28d5c",
"type": "debug",
"z": "1151076dd0552f2d",
"name": "debug 28",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1140,
"y": 1260,
"wires": []
}
]
This array has 5 items where 0 is the newest and 4 is the oldest.
As you can see, both item 0 and 2 has a status of DELIVERED
.
I want to do two things:
- First I want to look for any occurence of
DELIVERED
in the array. If the array contains a status ofDELIVERED
in any of the items, the message shall pass through a switch node. - Then, I want to set the payload to the array item with the oldest occurence of
DELIVERED
. So in this case, the payload should be set to{"status":"DELIVERED","dateIso":"2023-01-26T12:42:50+01:00"}
because item 2 is the oldest whereDELIVERED
appears.
How would I go on about this? This is just an example array - the array may have 10 items where every other item has DELIVERED
, for example.
Thanks!