mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Fix overwrite option on Merge-Node
This commit is contained in:
parent
642f857997
commit
c5d4c6a1d3
|
@ -179,14 +179,17 @@ export class Merge implements INodeType {
|
||||||
{
|
{
|
||||||
name: 'Always',
|
name: 'Always',
|
||||||
value: 'always',
|
value: 'always',
|
||||||
|
description: 'Always overwrites everything.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'If Blank',
|
||||||
|
value: 'blank',
|
||||||
|
description: 'Overwrites only values of "null", "undefined" or empty string.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'If Missing',
|
name: 'If Missing',
|
||||||
value: 'undefined',
|
value: 'undefined',
|
||||||
},
|
description: 'Only adds values which do not exist yet.',
|
||||||
{
|
|
||||||
name: 'If Blank',
|
|
||||||
value: 'blank'
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
default: 'always',
|
default: 'always',
|
||||||
|
@ -404,11 +407,18 @@ export class Merge implements INodeType {
|
||||||
entry = JSON.parse(JSON.stringify(entry));
|
entry = JSON.parse(JSON.stringify(entry));
|
||||||
|
|
||||||
for (key of Object.keys(copyData[referenceValue as string].json)) {
|
for (key of Object.keys(copyData[referenceValue as string].json)) {
|
||||||
// TODO: Currently only copies json data and no binary one
|
if (key === propertyName2) {
|
||||||
let value = copyData[referenceValue as string].json[key];
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (overwrite === 'always' || (overwrite === 'undefined' && ['null', 'undefined'].includes(typeof value)) || (overwrite === 'blank' && !value)) {
|
// TODO: Currently only copies json data and no binary one
|
||||||
entry.json[key] = value
|
const value = copyData[referenceValue as string].json[key];
|
||||||
|
if (
|
||||||
|
overwrite === 'always' ||
|
||||||
|
(overwrite === 'undefined' && !entry.json.hasOwnProperty(key)) ||
|
||||||
|
(overwrite === 'blank' && [null, undefined, ''].includes(entry.json[key] as string))
|
||||||
|
) {
|
||||||
|
entry.json[key] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue