Hello, I’m trying to replicate the solution from this topic ( Sum values with the same key), but I have two keys and can’t find out how to do that especially with this new Code node
Here is my data
{
"distance": sum of all jurisdictions distance,
"truck_no": "02",
"id": 498637
}
{
"distance": sum of all jurisdictions distance,
"truck_no": "12",
"id": 498645
}
Thank you very much! @eldala07 I know it should work perfectly but with new Code node it has much harder to find data, I hate this new Code especially with lack of documentation and examples. So I’m getting this if use $input.all() or items as data source.
Thank you @Jon it indeed works, but when I tried find data by myself I had problem. Usually when you put dot in the end of function or value you can see what is next in the structure but in this case I couldn’t see that. When for example I put the dot after current. (in this particulary case) I couldn’t see the following json and so on.
And the second question is how to deal with pagination. I would like to add data to the same output every iteration. Could you please tel me how to achieve that?
Thank you in advance.
Auto complete is an interesting one and doesn’t always work on variables which can make it a bit tricky, You can always type out the data manually though which isn’t so bad once you know how the data structure works.
Pagination would depend on the API you are using, What I like to do is wait for all the runs to complete then merge all the data and work with it from there. You can find an example on merging execution runs here: Merge multiple runs into one | n8n workflow template
Hey @Jon Thank you. I saw that solution but isn’t what I’m trying to achieve.
After each iteration I got sum of distance for particular “id” and I would like to continue that for the next page because it may contain the same “id” so I need somehow sum distance again. But I don’t need simply concatenate it in one list which will contains duplicate id’s.
It would be great if the Code node will do the same for each page and then sum the distance for particular “id” like it does for one iteration.
In that case I don’t think I fully understand what you are trying to do, Merging the execution runs then running the code node to do the maths should provide what you are after as it would loop through every item in one hit.
Sorry @Jon, my fault, I mixed it up at first. I put the nodes in the wrong sequence. Now everything works like clockwork, thanks a lot for your help.
I think it would be a good idea to create a “Transformation” node that would allow all operations to be done interactively rather than using programming skills.