mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 06:34:05 -08:00
⚡ Improve default code in Function nodes
This commit is contained in:
parent
bf1b496251
commit
6de666a675
|
@ -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,
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue