mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -08:00
fix(Google Sheets Node): Append or Update fails for numeric values
This commit is contained in:
parent
2327563c44
commit
b5e70d45bf
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue