Skip to content

Commit

Permalink
fix(Google Sheets Node): Append or Update fails for numeric values
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-radency authored Jan 5, 2023
1 parent 2327563 commit b5e70d4
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/nodes-base/nodes/Google/Sheet/v2/helpers/GoogleSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,15 +465,27 @@ export class GoogleSheet {
);
}

const columnValues =
const columnValues: Array<string | number> =
columnValuesList ||
(await this.getColumnValues(range, keyIndex, dataStartRowIndex, valueRenderMode));

const updateData: ISheetUpdateData[] = [];
const appendData: IDataObject[] = [];

const getKeyIndex = (key: string | number, data: Array<string | number>) => {
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) {
Expand All @@ -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) {
Expand Down

0 comments on commit b5e70d4

Please sign in to comment.