mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
🔀 Merge branch 'merge-overwrite' of https://github.com/TMaYaD/n8n into TMaYaD-merge-overwrite
This commit is contained in:
commit
642f857997
|
@ -164,6 +164,34 @@ export class Merge implements INodeType {
|
||||||
default: 'input1',
|
default: 'input1',
|
||||||
description: 'Defines of which input the data should be used as output of node.',
|
description: 'Defines of which input the data should be used as output of node.',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Overwrite',
|
||||||
|
name: 'overwrite',
|
||||||
|
type: 'options',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
mode: [
|
||||||
|
'mergeByKey',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Always',
|
||||||
|
value: 'always',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'If Missing',
|
||||||
|
value: 'undefined',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'If Blank',
|
||||||
|
value: 'blank'
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'always',
|
||||||
|
description: 'Select when to overwrite the values from Input1 with values from Input 2.',
|
||||||
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -285,6 +313,7 @@ export class Merge implements INodeType {
|
||||||
|
|
||||||
const propertyName1 = this.getNodeParameter('propertyName1', 0) as string;
|
const propertyName1 = this.getNodeParameter('propertyName1', 0) as string;
|
||||||
const propertyName2 = this.getNodeParameter('propertyName2', 0) as string;
|
const propertyName2 = this.getNodeParameter('propertyName2', 0) as string;
|
||||||
|
const overwrite = this.getNodeParameter('overwrite', 0) as string;
|
||||||
|
|
||||||
const dataInput2 = this.getInputData(1);
|
const dataInput2 = this.getInputData(1);
|
||||||
if (!dataInput2 || !propertyName1 || !propertyName2) {
|
if (!dataInput2 || !propertyName1 || !propertyName2) {
|
||||||
|
@ -376,7 +405,11 @@ export class Merge implements INodeType {
|
||||||
|
|
||||||
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
|
// TODO: Currently only copies json data and no binary one
|
||||||
entry.json[key] = copyData[referenceValue as string].json[key];
|
let value = copyData[referenceValue as string].json[key];
|
||||||
|
|
||||||
|
if (overwrite === 'always' || (overwrite === 'undefined' && ['null', 'undefined'].includes(typeof value)) || (overwrite === 'blank' && !value)) {
|
||||||
|
entry.json[key] = value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// For "keepKeyMatches" we add it as it is
|
// For "keepKeyMatches" we add it as it is
|
||||||
|
|
Loading…
Reference in a new issue