mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-27 13:39:44 -08:00
214 lines
4.5 KiB
JSON
214 lines
4.5 KiB
JSON
{
|
|
"nodes": [
|
|
{
|
|
"parameters": {},
|
|
"id": "33eede8d-2ab0-42ab-b79a-a069d8549ab0",
|
|
"name": "When clicking \"Execute Workflow\"",
|
|
"type": "n8n-nodes-base.manualTrigger",
|
|
"typeVersion": 1,
|
|
"position": [-40, 580]
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "return[\n { value: 1 },\n { value: 2 },\n]"
|
|
},
|
|
"id": "a5913b52-24dc-4f81-bb7f-f90e61dad978",
|
|
"name": "Sample Data",
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 1,
|
|
"position": [200, 580]
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "// Loop over input items and add a new field\n// called 'myNewField' to the JSON of each one\nlet sum = 0;\nfor (const item of $input.all()) {\n sum += item.json.value;\n}\n\nreturn [ {sum} ];"
|
|
},
|
|
"id": "c4ad4913-5af3-42bc-a784-69182f1facdd",
|
|
"name": "Run Once for All Items",
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 1,
|
|
"position": [460, 320]
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "// Loop over input items and add a new field\n// called 'myNewField' to the JSON of each one\nlet sum = 0;\nfor (const item of items) {\n sum += item.json.value;\n}\n\nreturn [ {sum} ];"
|
|
},
|
|
"id": "34cbd204-4335-4790-92cd-c3df617eee21",
|
|
"name": "Run Once for All Items (Legacy Syntax)",
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 1,
|
|
"position": [460, 500]
|
|
},
|
|
{
|
|
"parameters": {
|
|
"mode": "runOnceForEachItem",
|
|
"jsCode": "// Add a new field called 'myNewField' to the\n// JSON of the item\n$input.item.json.myNewField = $input.item.json.value;\n\nreturn $input.item;"
|
|
},
|
|
"id": "f67d29bf-554a-4572-8867-4456182dec24",
|
|
"name": "Run Once for Each Item",
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 1,
|
|
"position": [460, 680]
|
|
},
|
|
{
|
|
"parameters": {
|
|
"mode": "runOnceForEachItem",
|
|
"jsCode": "// Add a new field called 'myNewField' to the\n// JSON of the item\nitem.json.myNewField = item.json.value;\n\nreturn item;"
|
|
},
|
|
"id": "6f4bf149-e84e-4e0d-802a-7eaf7a42b18c",
|
|
"name": "Run Once for Each Item (Legacy Syntax)",
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 1,
|
|
"position": [460, 860]
|
|
},
|
|
{
|
|
"parameters": {
|
|
"mode": "runOnceForEachItem",
|
|
"jsCode": "const json = $input.item.json\njson.myNewField = await (async () => json.value)();\n\nreturn $input.item;"
|
|
},
|
|
"id": "3cff4a64-c3fd-47d3-a33e-3c446846138f",
|
|
"name": "With Async Functions",
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 1,
|
|
"position": [
|
|
460,
|
|
1200
|
|
]
|
|
},
|
|
{
|
|
"parameters": {
|
|
"mode": "runOnceForEachItem",
|
|
"jsCode": "const json = $input.item.json\njson.myNewField = await new Promise((resolve) => resolve(json.value));\n\nreturn $input.item;"
|
|
},
|
|
"id": "947e4e3e-2da3-40c5-97da-830c4572fc05",
|
|
"name": "With Promises",
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 1,
|
|
"position": [
|
|
460,
|
|
1380
|
|
]
|
|
}
|
|
],
|
|
"pinData": {
|
|
"Run Once for All Items": [
|
|
{
|
|
"json": {
|
|
"sum": 3
|
|
}
|
|
}
|
|
],
|
|
"Run Once for Each Item": [
|
|
{
|
|
"json": {
|
|
"value": 1,
|
|
"myNewField": 1
|
|
}
|
|
},
|
|
{
|
|
"json": {
|
|
"value": 2,
|
|
"myNewField": 2
|
|
}
|
|
}
|
|
],
|
|
"Run Once for All Items (Legacy Syntax)": [
|
|
{
|
|
"json": {
|
|
"sum": 3
|
|
}
|
|
}
|
|
],
|
|
"Run Once for Each Item (Legacy Syntax)": [
|
|
{
|
|
"json": {
|
|
"value": 1,
|
|
"myNewField": 1
|
|
}
|
|
},
|
|
{
|
|
"json": {
|
|
"value": 2,
|
|
"myNewField": 2
|
|
}
|
|
}
|
|
],
|
|
"With Async Functions": [
|
|
{
|
|
"json": {
|
|
"value": 1,
|
|
"myNewField": 1
|
|
}
|
|
},
|
|
{
|
|
"json": {
|
|
"value": 2,
|
|
"myNewField": 2
|
|
}
|
|
}
|
|
],
|
|
"With Promises": [
|
|
{
|
|
"json": {
|
|
"value": 1,
|
|
"myNewField": 1
|
|
}
|
|
},
|
|
{
|
|
"json": {
|
|
"value": 2,
|
|
"myNewField": 2
|
|
}
|
|
}
|
|
]
|
|
},
|
|
"connections": {
|
|
"When clicking \"Execute Workflow\"": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Sample Data",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Sample Data": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Run Once for All Items",
|
|
"type": "main",
|
|
"index": 0
|
|
},
|
|
{
|
|
"node": "Run Once for Each Item",
|
|
"type": "main",
|
|
"index": 0
|
|
},
|
|
{
|
|
"node": "Run Once for All Items (Legacy Syntax)",
|
|
"type": "main",
|
|
"index": 0
|
|
},
|
|
{
|
|
"node": "Run Once for Each Item (Legacy Syntax)",
|
|
"type": "main",
|
|
"index": 0
|
|
},
|
|
{
|
|
"node": "With Async Functions",
|
|
"type": "main",
|
|
"index": 0
|
|
},
|
|
{
|
|
"node": "With Promises",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
}
|
|
}
|
|
}
|