diff --git a/packages/nodes-base/nodes/Google/Sheet/v2/helpers/GoogleSheet.ts b/packages/nodes-base/nodes/Google/Sheet/v2/helpers/GoogleSheet.ts index 3f7ea99e65..0ad8667a47 100644 --- a/packages/nodes-base/nodes/Google/Sheet/v2/helpers/GoogleSheet.ts +++ b/packages/nodes-base/nodes/Google/Sheet/v2/helpers/GoogleSheet.ts @@ -465,15 +465,27 @@ export class GoogleSheet { ); } - const columnValues = + const columnValues: Array = columnValuesList || (await this.getColumnValues(range, keyIndex, dataStartRowIndex, valueRenderMode)); const updateData: ISheetUpdateData[] = []; const appendData: IDataObject[] = []; + const getKeyIndex = (key: string | number, data: Array) => { + let index = -1; + for (let i = 0; i < data.length; i++) { + if (data[i]?.toString() === key.toString()) { + index = i; + break; + } + } + return index; + }; + for (const item of inputData) { const inputIndexKey = item[indexKey] as string; + if (inputIndexKey === undefined || inputIndexKey === null) { // Item does not have the indexKey so we can ignore it or append it if upsert true if (upsert) { @@ -483,7 +495,8 @@ export class GoogleSheet { } // Item does have the key so check if it exists in Sheet - const indexOfIndexKeyInSheet = columnValues.indexOf(inputIndexKey); + const indexOfIndexKeyInSheet = getKeyIndex(inputIndexKey, columnValues); + if (indexOfIndexKeyInSheet === -1) { // Key does not exist in the Sheet so it can not be updated so skip it or append it if upsert true if (upsert) {