GroupBy field in set node [SOLVED]

Hello dear N8Ners! Could you please help with the following dataset? Is there a fast way to group it by contactID as a key, aggregating rest in array? Desirable data colored blue on screenshot. The data was prepared within one flow (branch).

Many-many thanks!

@mojome if I understand you correctly it sounds like you can do this with the Item Lists node -
Here is some more info about the node - Item Lists | Docs

Hi, David, unfortunally - no.


Aggregating via Item node unable to do grouping by key… or maybe I’m not aware of approach here.

@mojome - just thinking our loud here…
How about a merge node then the item lists node… (with the right settings that might give you the results you want)

Yep, I had the same idea. Were playing with items aggregate and merging with no result. The problem of merge node in this case is that the merging process is always inputting items without grouping even i have the merge by index mode.

Hey @mojome, welcome to the community :tada:

I think a combination of the Item Lists node suggested by @David_Go and a little bit of JS magic could do the trick here. First I use the Item Lists one to get my unique contactIDs, then I run the below code in a Function Item node to fetch the points and leadIDs foreach of them:

// First, read the items from the Mock Data node for our contact ID. Replace this name with the node you want to read your points and leadID from.
const data = $items("Mock Data").map(i => i.json).filter(i => i.contactID === item.contactID);

// Now write the points in a filed of our current unique item and remove null values
item.points = data.map(i => i.points).filter(i => i != null);

// Do the same for leadID
item.leadID = data.map(i => i.leadID).filter(i => i != null);

return item;
Example Workflow

I am using the .map() and .filter() methods here and this is the result:

2 Likes

@MutedJam very elegant low-code solution! Many thanks, I was circling around the .map() with the feeling that this could be the answer. Many thanks!

2 Likes