Skip to content

Commit 29ee4fa

Browse files
fix(Google Sheets Node): Fix "Append or Update" on an empty sheet (#9175)
Co-authored-by: Michael Kret <[email protected]>
1 parent f5ccb5f commit 29ee4fa

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

packages/editor-ui/src/components/ResourceMapper/ResourceMapper.vue

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { fieldCannotBeDeleted, parseResourceMapperFieldName } from '@/utils/node
1919
import { isResourceMapperValue } from '@/utils/typeGuards';
2020
import { i18n as locale } from '@/plugins/i18n';
2121
import { useNDVStore } from '@/stores/ndv.store';
22+
import { useWorkflowsStore } from '@/stores/workflows.store';
2223
2324
type Props = {
2425
parameter: INodeProperties;
@@ -32,6 +33,7 @@ type Props = {
3233
3334
const nodeTypesStore = useNodeTypesStore();
3435
const ndvStore = useNDVStore();
36+
const workflowsStore = useWorkflowsStore();
3537
3638
const props = withDefaults(defineProps<Props>(), {
3739
teleported: true,
@@ -71,6 +73,16 @@ watch(
7173
},
7274
);
7375
76+
// Reload fields to map when node is executed
77+
watch(
78+
() => workflowsStore.getWorkflowExecution,
79+
async (data) => {
80+
if (data?.status === 'success' && state.paramValue.mappingMode === 'autoMapInputData') {
81+
await initFetching(true);
82+
}
83+
},
84+
);
85+
7486
onMounted(async () => {
7587
if (props.node) {
7688
state.parameterValues = {
@@ -199,9 +211,9 @@ const pluralFieldWord = computed<string>(() => {
199211
);
200212
});
201213
202-
async function initFetching(inlineLading = false): Promise<void> {
214+
async function initFetching(inlineLoading = false): Promise<void> {
203215
state.loadingError = false;
204-
if (inlineLading) {
216+
if (inlineLoading) {
205217
state.refreshInProgress = true;
206218
} else {
207219
state.loading = true;

packages/nodes-base/nodes/Google/Sheet/v2/actions/sheet/appendOrUpdate.operation.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,18 +249,23 @@ export async function execute(
249249
}
250250
}
251251

252+
const dataMode =
253+
nodeVersion < 4
254+
? (this.getNodeParameter('dataMode', 0) as string)
255+
: (this.getNodeParameter('columns.mappingMode', 0) as string);
256+
252257
let columnNames: string[] = [];
253258

254-
const sheetData = await sheet.getData(sheetName, 'FORMATTED_VALUE');
259+
const sheetData = (await sheet.getData(sheetName, 'FORMATTED_VALUE')) ?? [];
255260

256-
if (sheetData?.[headerRow] === undefined) {
261+
if (!sheetData[headerRow] && dataMode !== 'autoMapInputData') {
257262
throw new NodeOperationError(
258263
this.getNode(),
259264
`Could not retrieve the column names from row ${headerRow + 1}`,
260265
);
261266
}
262267

263-
columnNames = sheetData[headerRow];
268+
columnNames = sheetData[headerRow] ?? [];
264269

265270
const newColumns = new Set<string>();
266271

@@ -269,11 +274,6 @@ export async function execute(
269274
? [this.getNodeParameter('columnToMatchOn', 0) as string]
270275
: (this.getNodeParameter('columns.matchingColumns', 0) as string[]);
271276

272-
const dataMode =
273-
nodeVersion < 4
274-
? (this.getNodeParameter('dataMode', 0) as string)
275-
: (this.getNodeParameter('columns.mappingMode', 0) as string);
276-
277277
// TODO: Add support for multiple columns to match on in the next overhaul
278278
const keyIndex = columnNames.indexOf(columnsToMatchOn[0]);
279279

@@ -379,6 +379,7 @@ export async function execute(
379379
headerRow + 1,
380380
);
381381
columnNames = newColumnNames;
382+
sheetData[headerRow] = newColumnNames;
382383
newColumns.clear();
383384
}
384385

packages/nodes-base/nodes/Google/Sheet/v2/helpers/GoogleSheet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ export class GoogleSheet {
476476

477477
const keyIndex = columnNames.indexOf(indexKey);
478478

479-
if (keyIndex === -1) {
479+
if (keyIndex === -1 && !upsert) {
480480
throw new NodeOperationError(
481481
this.executeFunctions.getNode(),
482482
`Could not find column for key "${indexKey}"`,

0 commit comments

Comments
 (0)