fix(Google Sheets Node): Insert data if sheet is empty instead of error (#10942)
This commit is contained in:
@@ -211,7 +211,7 @@ export async function execute(
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const items = this.getInputData();
|
||||
const nodeVersion = this.getNode().typeVersion;
|
||||
const dataMode =
|
||||
let dataMode =
|
||||
nodeVersion < 4
|
||||
? (this.getNodeParameter('dataMode', 0) as string)
|
||||
: (this.getNodeParameter('columns.mappingMode', 0) as string);
|
||||
@@ -228,6 +228,10 @@ export async function execute(
|
||||
|
||||
const sheetData = await sheet.getData(range, 'FORMATTED_VALUE');
|
||||
|
||||
if (sheetData === undefined || !sheetData.length) {
|
||||
dataMode = 'autoMapInputData';
|
||||
}
|
||||
|
||||
if (nodeVersion >= 4.4 && dataMode !== 'autoMapInputData') {
|
||||
//not possible to refresh columns when mode is autoMapInputData
|
||||
if (sheetData?.[keyRowIndex - 1] === undefined) {
|
||||
|
||||
@@ -257,7 +257,7 @@ export async function execute(
|
||||
}
|
||||
}
|
||||
|
||||
const dataMode =
|
||||
let dataMode =
|
||||
nodeVersion < 4
|
||||
? (this.getNodeParameter('dataMode', 0) as string)
|
||||
: (this.getNodeParameter('columns.mappingMode', 0) as string);
|
||||
@@ -267,10 +267,14 @@ export async function execute(
|
||||
const sheetData = (await sheet.getData(sheetName, 'FORMATTED_VALUE')) ?? [];
|
||||
|
||||
if (!sheetData[keyRowIndex] && dataMode !== 'autoMapInputData') {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Could not retrieve the column names from row ${keyRowIndex + 1}`,
|
||||
);
|
||||
if (!sheetData.length) {
|
||||
dataMode = 'autoMapInputData';
|
||||
} else {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
`Could not retrieve the column names from row ${keyRowIndex + 1}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
columnNames = sheetData[keyRowIndex] ?? [];
|
||||
|
||||
@@ -26,6 +26,13 @@ export const versionDescription: INodeTypeDescription = {
|
||||
whenToDisplay: 'beforeExecution',
|
||||
location: 'outputPane',
|
||||
},
|
||||
{
|
||||
message: 'No columns found in Google Sheet. All rows will be appended',
|
||||
displayCondition:
|
||||
'={{ ["appendOrUpdate", "append"].includes($parameter["operation"]) && $parameter?.columns?.mappingMode === "defineBelow" && !$parameter?.columns?.schema?.length }}',
|
||||
whenToDisplay: 'beforeExecution',
|
||||
location: 'outputPane',
|
||||
},
|
||||
],
|
||||
credentials: [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user