mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -08:00
fix(Google Sheets Node): Read operation execute for each item (#7800)
Github issue / Community forum post (link here to close automatically):
This commit is contained in:
parent
df691fba0c
commit
d5488725a8
|
@ -11,7 +11,7 @@ export class GoogleSheets extends VersionedNodeType {
|
|||
name: 'googleSheets',
|
||||
icon: 'file:googleSheets.svg',
|
||||
group: ['input', 'output'],
|
||||
defaultVersion: 4.1,
|
||||
defaultVersion: 4.2,
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Read, update and write data to Google Sheets',
|
||||
};
|
||||
|
@ -22,6 +22,7 @@ export class GoogleSheets extends VersionedNodeType {
|
|||
3: new GoogleSheetsV2(baseDescription),
|
||||
4: new GoogleSheetsV2(baseDescription),
|
||||
4.1: new GoogleSheetsV2(baseDescription),
|
||||
4.2: new GoogleSheetsV2(baseDescription),
|
||||
};
|
||||
|
||||
super(nodeVersions, baseDescription);
|
||||
|
|
|
@ -12,7 +12,7 @@ import type {
|
|||
SheetRangeData,
|
||||
ValueRenderOption,
|
||||
} from '../../helpers/GoogleSheets.types';
|
||||
import { generatePairedItemData } from '../../../../../../utils/utilities';
|
||||
|
||||
import { dataLocationOnSheet, outputFormatting } from './commonDescription';
|
||||
|
||||
export const description: SheetProperties = [
|
||||
|
@ -111,7 +111,18 @@ export async function execute(
|
|||
sheet: GoogleSheet,
|
||||
sheetName: string,
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const options = this.getNodeParameter('options', 0, {});
|
||||
const items = this.getInputData();
|
||||
const nodeVersion = this.getNode().typeVersion;
|
||||
let length = 1;
|
||||
|
||||
if (nodeVersion > 4.1) {
|
||||
length = items.length;
|
||||
}
|
||||
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
|
||||
for (let itemIndex = 0; itemIndex < length; itemIndex++) {
|
||||
const options = this.getNodeParameter('options', itemIndex, {});
|
||||
const outputFormattingOption =
|
||||
((options.outputFormatting as IDataObject)?.values as IDataObject) || {};
|
||||
|
||||
|
@ -138,22 +149,34 @@ export async function execute(
|
|||
return [];
|
||||
}
|
||||
|
||||
const { data, headerRow, firstDataRow } = prepareSheetData(sheetData, dataLocationOnSheetOptions);
|
||||
const { data, headerRow, firstDataRow } = prepareSheetData(
|
||||
sheetData,
|
||||
dataLocationOnSheetOptions,
|
||||
);
|
||||
|
||||
let responseData = [];
|
||||
|
||||
const lookupValues = this.getNodeParameter('filtersUI.values', 0, []) as ILookupValues[];
|
||||
const lookupValues = this.getNodeParameter(
|
||||
'filtersUI.values',
|
||||
itemIndex,
|
||||
[],
|
||||
) as ILookupValues[];
|
||||
|
||||
if (lookupValues.length) {
|
||||
const returnAllMatches = options.returnAllMatches === 'returnAllMatches' ? true : false;
|
||||
|
||||
const items = this.getInputData();
|
||||
if (nodeVersion <= 4.1) {
|
||||
for (let i = 1; i < items.length; i++) {
|
||||
const itemLookupValues = this.getNodeParameter('filtersUI.values', i, []) as ILookupValues[];
|
||||
const itemLookupValues = this.getNodeParameter(
|
||||
'filtersUI.values',
|
||||
i,
|
||||
[],
|
||||
) as ILookupValues[];
|
||||
if (itemLookupValues.length) {
|
||||
lookupValues.push(...itemLookupValues);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
responseData = await sheet.lookupValues(
|
||||
data as string[][],
|
||||
|
@ -166,15 +189,15 @@ export async function execute(
|
|||
responseData = sheet.structureArrayDataByColumn(data as string[][], headerRow, firstDataRow);
|
||||
}
|
||||
|
||||
const items = this.getInputData();
|
||||
const pairedItem = generatePairedItemData(items.length);
|
||||
|
||||
const returnData: INodeExecutionData[] = responseData.map((item, index) => {
|
||||
returnData.push(
|
||||
...responseData.map((item, index) => {
|
||||
return {
|
||||
json: item,
|
||||
pairedItem,
|
||||
pairedItem: { item: itemIndex },
|
||||
};
|
||||
});
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ export const versionDescription: INodeTypeDescription = {
|
|||
name: 'googleSheets',
|
||||
icon: 'file:googleSheets.svg',
|
||||
group: ['input', 'output'],
|
||||
version: [3, 4, 4.1],
|
||||
version: [3, 4, 4.1, 4.2],
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Read, update and write data to Google Sheets',
|
||||
defaults: {
|
||||
|
|
Loading…
Reference in a new issue