Improve default code in Function nodes

This commit is contained in:
Jan Oberhauser 2021-05-29 14:03:59 -05:00
parent bf1b496251
commit 6de666a675
2 changed files with 22 additions and 2 deletions

View file

@ -32,7 +32,18 @@ export class Function implements INodeType {
rows: 10,
},
type: 'string',
default: 'items[0].json.myVariable = 1;\nreturn items;',
default: `// Code here will run only once, no matter how many input items there are.
// More info and help: https://docs.n8n.io/nodes/n8n-nodes-base.function
// Loop over inputs and add a new field called 'myNewField' to the JSON of each one
for (item of items) {
item.json.myNewField = 1;
}
// You can write logs to the browser console
console.log('Done!');
return items;`,
description: 'The JavaScript code to execute.',
noDataExpression: true,
},

View file

@ -34,7 +34,16 @@ export class FunctionItem implements INodeType {
rows: 10,
},
type: 'string',
default: 'item.myVariable = 1;\nreturn item;',
default: `// Code here will run once per input item.
// More info and help: https://docs.n8n.io/nodes/n8n-nodes-base.functionItem
// Add a new field called 'myNewField' to the JSON of the item
item.myNewField = 1;
// You can write logs to the browser console
console.log('Done!');
return item;`,
description: 'The JavaScript code to execute for each item.',
noDataExpression: true,
},