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:
Michael Kret 2023-11-28 11:02:11 +02:00 committed by GitHub
parent df691fba0c
commit d5488725a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 81 additions and 57 deletions

View file

@ -11,7 +11,7 @@ export class GoogleSheets extends VersionedNodeType {
name: 'googleSheets', name: 'googleSheets',
icon: 'file:googleSheets.svg', icon: 'file:googleSheets.svg',
group: ['input', 'output'], group: ['input', 'output'],
defaultVersion: 4.1, defaultVersion: 4.2,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Read, update and write data to Google Sheets', description: 'Read, update and write data to Google Sheets',
}; };
@ -22,6 +22,7 @@ export class GoogleSheets extends VersionedNodeType {
3: new GoogleSheetsV2(baseDescription), 3: new GoogleSheetsV2(baseDescription),
4: new GoogleSheetsV2(baseDescription), 4: new GoogleSheetsV2(baseDescription),
4.1: new GoogleSheetsV2(baseDescription), 4.1: new GoogleSheetsV2(baseDescription),
4.2: new GoogleSheetsV2(baseDescription),
}; };
super(nodeVersions, baseDescription); super(nodeVersions, baseDescription);

View file

@ -12,7 +12,7 @@ import type {
SheetRangeData, SheetRangeData,
ValueRenderOption, ValueRenderOption,
} from '../../helpers/GoogleSheets.types'; } from '../../helpers/GoogleSheets.types';
import { generatePairedItemData } from '../../../../../../utils/utilities';
import { dataLocationOnSheet, outputFormatting } from './commonDescription'; import { dataLocationOnSheet, outputFormatting } from './commonDescription';
export const description: SheetProperties = [ export const description: SheetProperties = [
@ -111,7 +111,18 @@ export async function execute(
sheet: GoogleSheet, sheet: GoogleSheet,
sheetName: string, sheetName: string,
): Promise<INodeExecutionData[]> { ): 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 = const outputFormattingOption =
((options.outputFormatting as IDataObject)?.values as IDataObject) || {}; ((options.outputFormatting as IDataObject)?.values as IDataObject) || {};
@ -138,22 +149,34 @@ export async function execute(
return []; return [];
} }
const { data, headerRow, firstDataRow } = prepareSheetData(sheetData, dataLocationOnSheetOptions); const { data, headerRow, firstDataRow } = prepareSheetData(
sheetData,
dataLocationOnSheetOptions,
);
let responseData = []; let responseData = [];
const lookupValues = this.getNodeParameter('filtersUI.values', 0, []) as ILookupValues[]; const lookupValues = this.getNodeParameter(
'filtersUI.values',
itemIndex,
[],
) as ILookupValues[];
if (lookupValues.length) { if (lookupValues.length) {
const returnAllMatches = options.returnAllMatches === 'returnAllMatches' ? true : false; const returnAllMatches = options.returnAllMatches === 'returnAllMatches' ? true : false;
const items = this.getInputData(); if (nodeVersion <= 4.1) {
for (let i = 1; i < items.length; i++) { 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) { if (itemLookupValues.length) {
lookupValues.push(...itemLookupValues); lookupValues.push(...itemLookupValues);
} }
} }
}
responseData = await sheet.lookupValues( responseData = await sheet.lookupValues(
data as string[][], data as string[][],
@ -166,15 +189,15 @@ export async function execute(
responseData = sheet.structureArrayDataByColumn(data as string[][], headerRow, firstDataRow); responseData = sheet.structureArrayDataByColumn(data as string[][], headerRow, firstDataRow);
} }
const items = this.getInputData(); returnData.push(
const pairedItem = generatePairedItemData(items.length); ...responseData.map((item, index) => {
const returnData: INodeExecutionData[] = responseData.map((item, index) => {
return { return {
json: item, json: item,
pairedItem, pairedItem: { item: itemIndex },
}; };
}); }),
);
}
return returnData; return returnData;
} }

View file

@ -9,7 +9,7 @@ export const versionDescription: INodeTypeDescription = {
name: 'googleSheets', name: 'googleSheets',
icon: 'file:googleSheets.svg', icon: 'file:googleSheets.svg',
group: ['input', 'output'], group: ['input', 'output'],
version: [3, 4, 4.1], version: [3, 4, 4.1, 4.2],
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Read, update and write data to Google Sheets', description: 'Read, update and write data to Google Sheets',
defaults: { defaults: {