mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 20: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,70 +111,93 @@ export async function execute(
|
|||
sheet: GoogleSheet,
|
||||
sheetName: string,
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const options = this.getNodeParameter('options', 0, {});
|
||||
const outputFormattingOption =
|
||||
((options.outputFormatting as IDataObject)?.values as IDataObject) || {};
|
||||
const items = this.getInputData();
|
||||
const nodeVersion = this.getNode().typeVersion;
|
||||
let length = 1;
|
||||
|
||||
const dataLocationOnSheetOptions =
|
||||
((options.dataLocationOnSheet as IDataObject)?.values as RangeDetectionOptions) || {};
|
||||
|
||||
if (dataLocationOnSheetOptions.rangeDefinition === undefined) {
|
||||
dataLocationOnSheetOptions.rangeDefinition = 'detectAutomatically';
|
||||
if (nodeVersion > 4.1) {
|
||||
length = items.length;
|
||||
}
|
||||
|
||||
const range = getRangeString(sheetName, dataLocationOnSheetOptions);
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
|
||||
const valueRenderMode = (outputFormattingOption.general ||
|
||||
'UNFORMATTED_VALUE') as ValueRenderOption;
|
||||
const dateTimeRenderOption = (outputFormattingOption.date || 'FORMATTED_STRING') as string;
|
||||
for (let itemIndex = 0; itemIndex < length; itemIndex++) {
|
||||
const options = this.getNodeParameter('options', itemIndex, {});
|
||||
const outputFormattingOption =
|
||||
((options.outputFormatting as IDataObject)?.values as IDataObject) || {};
|
||||
|
||||
const sheetData = (await sheet.getData(
|
||||
range,
|
||||
valueRenderMode,
|
||||
dateTimeRenderOption,
|
||||
)) as SheetRangeData;
|
||||
const dataLocationOnSheetOptions =
|
||||
((options.dataLocationOnSheet as IDataObject)?.values as RangeDetectionOptions) || {};
|
||||
|
||||
if (sheetData === undefined || sheetData.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const { data, headerRow, firstDataRow } = prepareSheetData(sheetData, dataLocationOnSheetOptions);
|
||||
|
||||
let responseData = [];
|
||||
|
||||
const lookupValues = this.getNodeParameter('filtersUI.values', 0, []) as ILookupValues[];
|
||||
|
||||
if (lookupValues.length) {
|
||||
const returnAllMatches = options.returnAllMatches === 'returnAllMatches' ? true : false;
|
||||
|
||||
const items = this.getInputData();
|
||||
for (let i = 1; i < items.length; i++) {
|
||||
const itemLookupValues = this.getNodeParameter('filtersUI.values', i, []) as ILookupValues[];
|
||||
if (itemLookupValues.length) {
|
||||
lookupValues.push(...itemLookupValues);
|
||||
}
|
||||
if (dataLocationOnSheetOptions.rangeDefinition === undefined) {
|
||||
dataLocationOnSheetOptions.rangeDefinition = 'detectAutomatically';
|
||||
}
|
||||
|
||||
responseData = await sheet.lookupValues(
|
||||
data as string[][],
|
||||
headerRow,
|
||||
firstDataRow,
|
||||
lookupValues,
|
||||
returnAllMatches,
|
||||
const range = getRangeString(sheetName, dataLocationOnSheetOptions);
|
||||
|
||||
const valueRenderMode = (outputFormattingOption.general ||
|
||||
'UNFORMATTED_VALUE') as ValueRenderOption;
|
||||
const dateTimeRenderOption = (outputFormattingOption.date || 'FORMATTED_STRING') as string;
|
||||
|
||||
const sheetData = (await sheet.getData(
|
||||
range,
|
||||
valueRenderMode,
|
||||
dateTimeRenderOption,
|
||||
)) as SheetRangeData;
|
||||
|
||||
if (sheetData === undefined || sheetData.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const { data, headerRow, firstDataRow } = prepareSheetData(
|
||||
sheetData,
|
||||
dataLocationOnSheetOptions,
|
||||
);
|
||||
|
||||
let responseData = [];
|
||||
|
||||
const lookupValues = this.getNodeParameter(
|
||||
'filtersUI.values',
|
||||
itemIndex,
|
||||
[],
|
||||
) as ILookupValues[];
|
||||
|
||||
if (lookupValues.length) {
|
||||
const returnAllMatches = options.returnAllMatches === 'returnAllMatches' ? true : false;
|
||||
|
||||
if (nodeVersion <= 4.1) {
|
||||
for (let i = 1; i < items.length; i++) {
|
||||
const itemLookupValues = this.getNodeParameter(
|
||||
'filtersUI.values',
|
||||
i,
|
||||
[],
|
||||
) as ILookupValues[];
|
||||
if (itemLookupValues.length) {
|
||||
lookupValues.push(...itemLookupValues);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
responseData = await sheet.lookupValues(
|
||||
data as string[][],
|
||||
headerRow,
|
||||
firstDataRow,
|
||||
lookupValues,
|
||||
returnAllMatches,
|
||||
);
|
||||
} else {
|
||||
responseData = sheet.structureArrayDataByColumn(data as string[][], headerRow, firstDataRow);
|
||||
}
|
||||
|
||||
returnData.push(
|
||||
...responseData.map((item, index) => {
|
||||
return {
|
||||
json: item,
|
||||
pairedItem: { item: itemIndex },
|
||||
};
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
responseData = sheet.structureArrayDataByColumn(data as string[][], headerRow, firstDataRow);
|
||||
}
|
||||
|
||||
const items = this.getInputData();
|
||||
const pairedItem = generatePairedItemData(items.length);
|
||||
|
||||
const returnData: INodeExecutionData[] = responseData.map((item, index) => {
|
||||
return {
|
||||
json: item,
|
||||
pairedItem,
|
||||
};
|
||||
});
|
||||
|
||||
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