I have an issue to find out how i could map a certain data object from a (array/list) in a json to a object in next node. I would like to find the right object value based on the object id. So i would in below example like to set a objectvalue in a second node that have “objectId”. I hope you understand.
Also I am not sure how your data looks like exactly. If you have the data in different items instead of one (like @RicardoE105 solution) something like that would be possible:
Theoretically could you also do the find directly in an expression on the parameter but it seems like that it parses something wrong. Because if I do that I always get the error message: Malformed arrow function parameter list).
So an additional step via a Function-Nodes like either @RicardoE105 or I did is sadly needed.
Thanks for the help i did try it out but i realise that i forgot to add one thing
I would like to map 3 object in the second node but there is only data for 2 of them in the json. can i still make the node process the 2 that gets data but ignore last one.
"nodes": [
{
"parameters": {
"functionCode": "return {\n atd: item[\"evetData\"][\"Objects\"].find(data => data.objectId === 'object1').objectvalue,\n etd: item[\"evetData\"][\"Objects\"].find(data => data.objectId === 'object2').objectvalue,\n etx: item[\"evetData\"][\"Objects\"].find(data => data.objectId === 'object19').objectvalue\n \n \n}\n"
},
"name": "GetValue",
"type": "n8n-nodes-base.functionItem",
"typeVersion": 1,
"position": [
650,
450
]
},
{
"parameters": {
"functionCode": "return [\n {\n json: {\n \"evetData\":{\n \"Objects\":[\n {\n \"objectId\": \"object1\",\n \"objectvalue\": \"10\"\n },\n {\n \"objectId\": \"object2\",\n \"objectvalue\": \"20\"\n }\n ]\n }\n }\n },\n {\n json: {\n \"evetData\":{\n \"Objects\":[\n {\n \"objectId\": \"object3\",\n \"objectvalue\": \"22\"\n },\n {\n \"objectId\": \"object2\",\n \"objectvalue\": \"20\"\n },\n {\n \"objectId\": \"object1\",\n \"objectvalue\": \"100\"\n }\n ]\n }\n }\n },\n]"
},
"name": "MockData",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
450,
450
]
},
{
"parameters": {
"values": {
"string": [
{
"name": "recivedobjectValue",
"value": "={{$node[\"GetValue\"].json[\"recivedobjectValue\"]}}"
}
]
},
"options": {}
},
"name": "Set",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [
850,
450
]
}
],
"connections": {
"GetValue": {
"main": [
[
{
"node": "Set",
"type": "main",
"index": 0
}
]
]
},
"MockData": {
"main": [
[
{
"node": "GetValue",
"type": "main",
"index": 0
}
]
]
}
}
}
By the way i hope i made right now with code added to the post.
We are starting to get more and more of the concept struggling with some of the code in the nodes. But like i said many times before it is a great software.