fix(Google Sheets Node): Append fails if cells have some default values added by data validation rules (#9950)
This commit is contained in:
@@ -237,15 +237,15 @@ export async function execute(
|
||||
|
||||
const locationDefineOptions = (options.locationDefine as IDataObject)?.values as IDataObject;
|
||||
|
||||
let headerRow = 0;
|
||||
let firstDataRow = 1;
|
||||
let keyRowIndex = 0;
|
||||
let dataStartRowIndex = 1;
|
||||
|
||||
if (locationDefineOptions) {
|
||||
if (locationDefineOptions.headerRow) {
|
||||
headerRow = parseInt(locationDefineOptions.headerRow as string, 10) - 1;
|
||||
keyRowIndex = parseInt(locationDefineOptions.headerRow as string, 10) - 1;
|
||||
}
|
||||
if (locationDefineOptions.firstDataRow) {
|
||||
firstDataRow = parseInt(locationDefineOptions.firstDataRow as string, 10) - 1;
|
||||
dataStartRowIndex = parseInt(locationDefineOptions.firstDataRow as string, 10) - 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,14 +253,14 @@ export async function execute(
|
||||
|
||||
const sheetData = await sheet.getData(sheetName, 'FORMATTED_VALUE');
|
||||
|
||||
if (sheetData?.[headerRow] === undefined) {
|
||||
if (sheetData?.[keyRowIndex] === undefined) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Could not retrieve the column names from row ${headerRow + 1}`,
|
||||
`Could not retrieve the column names from row ${keyRowIndex + 1}`,
|
||||
);
|
||||
}
|
||||
|
||||
columnNames = sheetData[headerRow];
|
||||
columnNames = sheetData[keyRowIndex];
|
||||
|
||||
if (nodeVersion >= 4.4) {
|
||||
const schema = this.getNodeParameter('columns.schema', 0) as ResourceMapperField[];
|
||||
@@ -283,13 +283,13 @@ export async function execute(
|
||||
const keyIndex = columnNames.indexOf(columnsToMatchOn[0]);
|
||||
|
||||
//not used when updating row
|
||||
const columnValues = await sheet.getColumnValues(
|
||||
const columnValuesList = await sheet.getColumnValues({
|
||||
range,
|
||||
keyIndex,
|
||||
firstDataRow,
|
||||
dataStartRowIndex,
|
||||
valueRenderMode,
|
||||
sheetData,
|
||||
);
|
||||
});
|
||||
|
||||
const updateData: ISheetUpdateData[] = [];
|
||||
|
||||
@@ -313,20 +313,20 @@ export async function execute(
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
if (dataMode === 'nothing') continue;
|
||||
|
||||
const data: IDataObject[] = [];
|
||||
const inputData: IDataObject[] = [];
|
||||
|
||||
if (dataMode === 'autoMapInputData') {
|
||||
const handlingExtraDataOption = (options.handlingExtraData as string) || 'insertInNewColumn';
|
||||
if (handlingExtraDataOption === 'ignoreIt') {
|
||||
data.push(items[i].json);
|
||||
inputData.push(items[i].json);
|
||||
}
|
||||
if (handlingExtraDataOption === 'error' && columnsToMatchOn[0] !== 'row_number') {
|
||||
Object.keys(items[i].json).forEach((key) => errorOnUnexpectedColumn(key, i));
|
||||
data.push(items[i].json);
|
||||
inputData.push(items[i].json);
|
||||
}
|
||||
if (handlingExtraDataOption === 'insertInNewColumn' && columnsToMatchOn[0] !== 'row_number') {
|
||||
Object.keys(items[i].json).forEach(addNewColumn);
|
||||
data.push(items[i].json);
|
||||
inputData.push(items[i].json);
|
||||
}
|
||||
} else {
|
||||
const valueToMatchOn =
|
||||
@@ -360,7 +360,7 @@ export async function execute(
|
||||
|
||||
fields[columnsToMatchOn[0]] = valueToMatchOn;
|
||||
|
||||
data.push(fields);
|
||||
inputData.push(fields);
|
||||
} else {
|
||||
const mappingValues = this.getNodeParameter('columns.value', i) as IDataObject;
|
||||
if (Object.keys(mappingValues).length === 0) {
|
||||
@@ -375,7 +375,7 @@ export async function execute(
|
||||
mappingValues[key] = '';
|
||||
}
|
||||
});
|
||||
data.push(mappingValues);
|
||||
inputData.push(mappingValues);
|
||||
mappedValues.push(mappingValues);
|
||||
}
|
||||
}
|
||||
@@ -386,29 +386,30 @@ export async function execute(
|
||||
sheetName,
|
||||
[newColumnNames],
|
||||
(options.cellFormat as ValueInputOption) || cellFormatDefault(nodeVersion),
|
||||
headerRow + 1,
|
||||
keyRowIndex + 1,
|
||||
);
|
||||
columnNames = newColumnNames;
|
||||
newColumns.clear();
|
||||
}
|
||||
|
||||
let preparedData;
|
||||
const columnNamesList = [columnNames.concat([...newColumns])];
|
||||
|
||||
if (columnsToMatchOn[0] === 'row_number') {
|
||||
preparedData = sheet.prepareDataForUpdatingByRowNumber(data, range, [
|
||||
columnNames.concat([...newColumns]),
|
||||
]);
|
||||
preparedData = sheet.prepareDataForUpdatingByRowNumber(inputData, range, columnNamesList);
|
||||
} else {
|
||||
preparedData = await sheet.prepareDataForUpdateOrUpsert(
|
||||
data,
|
||||
columnsToMatchOn[0],
|
||||
const indexKey = columnsToMatchOn[0];
|
||||
|
||||
preparedData = await sheet.prepareDataForUpdateOrUpsert({
|
||||
inputData,
|
||||
indexKey,
|
||||
range,
|
||||
headerRow,
|
||||
firstDataRow,
|
||||
keyRowIndex,
|
||||
dataStartRowIndex,
|
||||
valueRenderMode,
|
||||
false,
|
||||
[columnNames.concat([...newColumns])],
|
||||
columnValues,
|
||||
);
|
||||
columnNamesList,
|
||||
columnValuesList,
|
||||
});
|
||||
}
|
||||
|
||||
updateData.push(...preparedData.updateData);
|
||||
|
||||
Reference in New Issue
Block a user