-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Execution Data Node): New node (#6247)
- Loading branch information
1 parent
96144bd
commit 3f7c4f0
Showing
3 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
packages/nodes-base/nodes/ExecutionData/ExecutionData.node.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"node": "n8n-nodes-base.executionData", | ||
"nodeVersion": "1.0", | ||
"codexVersion": "1.0", | ||
"categories": ["Development", "Core Nodes"], | ||
"subcategories": { | ||
"Core Nodes": ["Helpers"] | ||
}, | ||
"resources": { | ||
"credentialDocumentation": [ | ||
{ | ||
"url": "https://docs.n8n.io/credentials/executionData" | ||
} | ||
], | ||
"primaryDocumentation": [ | ||
{ | ||
"url": "https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.executionData/" | ||
} | ||
] | ||
}, | ||
"alias": ["Filter", "Set", "Data"] | ||
} |
111 changes: 111 additions & 0 deletions
111
packages/nodes-base/nodes/ExecutionData/ExecutionData.node.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* eslint-disable n8n-nodes-base/node-class-description-missing-subtitle */ | ||
import type { | ||
IDataObject, | ||
IExecuteFunctions, | ||
INodeExecutionData, | ||
INodeType, | ||
INodeTypeDescription, | ||
} from 'n8n-workflow'; | ||
|
||
export class ExecutionData implements INodeType { | ||
description: INodeTypeDescription = { | ||
displayName: 'Execution Data', | ||
name: 'executionData', | ||
icon: 'fa:tasks', | ||
group: ['input'], | ||
version: 1, | ||
description: 'Add execution data for search', | ||
defaults: { | ||
name: 'Execution Data', | ||
color: '#29A568', | ||
}, | ||
inputs: ['main'], | ||
outputs: ['main'], | ||
properties: [ | ||
{ | ||
displayName: | ||
"Use this node to save fields you want to use later to easily find an execution (e.g. a user ID). You'll be able to search by this data in the 'executions' tab.<br>This feature is available on our Pro and Enterprise plans. <a href='https://n8n.io/pricing/' target='_blank'>More Info</a>.", | ||
name: 'notice', | ||
type: 'notice', | ||
default: '', | ||
}, | ||
{ | ||
displayName: 'Operation', | ||
name: 'operation', | ||
type: 'options', | ||
default: 'save', | ||
noDataExpression: true, | ||
options: [ | ||
{ | ||
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased | ||
name: 'Save Execution Data for Search', | ||
value: 'save', | ||
action: 'Save execution data for search', | ||
}, | ||
], | ||
}, | ||
{ | ||
displayName: 'Data to Save', | ||
name: 'dataToSave', | ||
placeholder: 'Add Saved Field', | ||
type: 'fixedCollection', | ||
typeOptions: { | ||
multipleValueButtonText: 'Add Saved Field', | ||
multipleValues: true, | ||
}, | ||
displayOptions: { | ||
show: { | ||
operation: ['save'], | ||
}, | ||
}, | ||
default: {}, | ||
options: [ | ||
{ | ||
displayName: 'Values', | ||
name: 'values', | ||
values: [ | ||
{ | ||
displayName: 'Key', | ||
name: 'key', | ||
type: 'string', | ||
default: '', | ||
placeholder: 'e.g. myKey', | ||
}, | ||
{ | ||
displayName: 'Value', | ||
name: 'value', | ||
type: 'string', | ||
default: '', | ||
placeholder: 'e.g. myValue', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> { | ||
const context = this.getWorkflowDataProxy(0); | ||
|
||
const items = this.getInputData(); | ||
const operations = this.getNodeParameter('operation', 0); | ||
|
||
if (operations === 'save') { | ||
for (let i = 0; i < items.length; i++) { | ||
const dataToSave = | ||
((this.getNodeParameter('dataToSave', i, {}) as IDataObject).values as IDataObject[]) || | ||
[]; | ||
|
||
const values = dataToSave.reduce((acc, { key, value }) => { | ||
acc[key as string] = value; | ||
return acc; | ||
}, {} as IDataObject); | ||
|
||
context.$execution.customData.setAll(values); | ||
} | ||
} | ||
|
||
return [items]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters