Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Item Lists Node): Concatenate operation pairedItems fix #7286

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/nodes-base/nodes/ItemLists/V2/ItemListsV2.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
INodeType,
INodeTypeBaseDescription,
INodeTypeDescription,
IPairedItemData,
} from 'n8n-workflow';
import { NodeOperationError, deepCopy } from 'n8n-workflow';

Expand Down Expand Up @@ -1103,6 +1104,7 @@ return 0;`,
return [returnData];
} else {
let newItems: IDataObject[] = items.map((item) => item.json);
let pairedItem: IPairedItemData[] = [];
const destinationFieldName = this.getNodeParameter('destinationFieldName', 0) as string;
const fieldsToExclude = (
this.getNodeParameter('fieldsToExclude.fields', 0, []) as IDataObject[]
Expand All @@ -1112,7 +1114,7 @@ return 0;`,
).map((entry) => entry.fieldName);

if (fieldsToExclude.length || fieldsToInclude.length) {
newItems = newItems.reduce((acc, item) => {
newItems = newItems.reduce((acc, item, index) => {
const newItem: IDataObject = {};
let outputFields = Object.keys(item);

Expand All @@ -1132,11 +1134,16 @@ return 0;`,
if (isEmpty(newItem)) {
return acc;
}
pairedItem.push({ item: index });
return acc.concat([newItem]);
}, [] as IDataObject[]);
} else {
pairedItem = Array.from({ length: newItems.length }, (_, item) => ({
item,
}));
}

return [[{ json: { [destinationFieldName]: newItems } }]];
return [[{ json: { [destinationFieldName]: newItems }, pairedItem }]];
}
} else if (operation === 'removeDuplicates') {
const compare = this.getNodeParameter('compare', 0) as string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
IExecuteFunctions,
INodeExecutionData,
INodeProperties,
IPairedItemData,
} from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';

Expand Down Expand Up @@ -307,6 +308,7 @@ export async function execute(
returnData.push(newItem);
} else {
let newItems: IDataObject[] = items.map((item) => item.json);
let pairedItem: IPairedItemData[] = [];
const destinationFieldName = this.getNodeParameter('destinationFieldName', 0) as string;

const fieldsToExclude = prepareFieldsArray(
Expand All @@ -320,7 +322,7 @@ export async function execute(
);

if (fieldsToExclude.length || fieldsToInclude.length) {
newItems = newItems.reduce((acc, item) => {
newItems = newItems.reduce((acc, item, index) => {
const newItem: IDataObject = {};
let outputFields = Object.keys(item);

Expand All @@ -340,12 +342,17 @@ export async function execute(
if (isEmpty(newItem)) {
return acc;
}

pairedItem.push({ item: index });
return acc.concat([newItem]);
}, [] as IDataObject[]);
} else {
pairedItem = Array.from({ length: newItems.length }, (_, item) => ({
item,
}));
}

const output: INodeExecutionData = { json: { [destinationFieldName]: newItems } };

const output: INodeExecutionData = { json: { [destinationFieldName]: newItems }, pairedItem };
returnData.push(output);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
{
"name": "itemsList concatenate paired fix",
"nodes": [
{
"parameters": {},
"id": "37256a71-67fe-4643-b4c7-e670096b68fc",
"name": "When clicking \"Execute Workflow\"",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
620,
540
]
},
{
"parameters": {
"category": "randomData",
"randomDataSeed": "n8n",
"randomDataCount": 3
},
"id": "0518c1d3-2e6d-40c6-8225-d89ec28ed28d",
"name": "DebugHelper",
"type": "n8n-nodes-base.debugHelper",
"typeVersion": 1,
"position": [
1000,
540
]
},
{
"parameters": {
"operation": "concatenateItems",
"aggregate": "aggregateAllItemData"
},
"id": "7866056b-a7c1-41e2-b3b7-301cb21d95d4",
"name": "Item Lists",
"type": "n8n-nodes-base.itemLists",
"typeVersion": 3,
"position": [
1200,
540
]
},
{
"parameters": {
"fields": {
"values": [
{
"name": "foo",
"stringValue": "bar"
}
]
},
"options": {}
},
"id": "191ec112-65b6-4e4a-bf11-b63ab7e96f68",
"name": "Edit Fields",
"type": "n8n-nodes-base.set",
"typeVersion": 3,
"position": [
800,
540
]
},
{
"parameters": {
"customerId": "1",
"message": "={{ $('Edit Fields').item.json.foo }}"
},
"id": "4a3d6844-5044-4570-912a-af3f32efa871",
"name": "Customer Messenger (n8n training)",
"type": "n8n-nodes-base.n8nTrainingCustomerMessenger",
"typeVersion": 1,
"position": [
1400,
540
]
}
],
"pinData": {
"Customer Messenger (n8n training)": [
{
"json": {
"output": "Sent message to customer 1: bar"
}
}
]
},
"connections": {
"When clicking \"Execute Workflow\"": {
"main": [
[
{
"node": "Edit Fields",
"type": "main",
"index": 0
}
]
]
},
"DebugHelper": {
"main": [
[
{
"node": "Item Lists",
"type": "main",
"index": 0
}
]
]
},
"Item Lists": {
"main": [
[
{
"node": "Customer Messenger (n8n training)",
"type": "main",
"index": 0
}
]
]
},
"Edit Fields": {
"main": [
[
{
"node": "DebugHelper",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "d17719c9-c625-4419-8b3c-d4cfaeffc312",
"id": "vXdwDVBSRxZxMrcv",
"meta": {
"instanceId": "b888bd11cd1ddbb95450babf3e199556799d999b896f650de768b8370ee50363"
},
"tags": []
}
Loading