🔀 Merge branch 'merge-overwrite' of https://github.com/TMaYaD/n8n into TMaYaD-merge-overwrite

This commit is contained in:
Jan Oberhauser 2020-01-19 11:12:49 -06:00
commit 642f857997

View file

@ -164,6 +164,34 @@ export class Merge implements INodeType {
default: 'input1',
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 propertyName2 = this.getNodeParameter('propertyName2', 0) as string;
const overwrite = this.getNodeParameter('overwrite', 0) as string;
const dataInput2 = this.getInputData(1);
if (!dataInput2 || !propertyName1 || !propertyName2) {
@ -376,7 +405,11 @@ export class Merge implements INodeType {
for (key of Object.keys(copyData[referenceValue as string].json)) {
// 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 {
// For "keepKeyMatches" we add it as it is