fix(Google Sheets Node): Append or Update fails for numeric values

This commit is contained in:
Michael Kret 2023-01-05 17:31:47 +02:00 committed by GitHub
parent 2327563c44
commit b5e70d45bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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) {
@ -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) {