Skip to content

Commit

Permalink
feat(Execution Data Node): New node (#6247)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-radency committed May 24, 2023
1 parent 96144bd commit 3f7c4f0
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/nodes-base/nodes/ExecutionData/ExecutionData.node.json
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 packages/nodes-base/nodes/ExecutionData/ExecutionData.node.ts
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];
}
}
1 change: 1 addition & 0 deletions packages/nodes-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@
"dist/nodes/ExecuteCommand/ExecuteCommand.node.js",
"dist/nodes/ExecuteWorkflow/ExecuteWorkflow.node.js",
"dist/nodes/ExecuteWorkflowTrigger/ExecuteWorkflowTrigger.node.js",
"dist/nodes/ExecutionData/ExecutionData.node.js",
"dist/nodes/Facebook/FacebookGraphApi.node.js",
"dist/nodes/Facebook/FacebookTrigger.node.js",
"dist/nodes/Figma/FigmaTrigger.node.js",
Expand Down

0 comments on commit 3f7c4f0

Please sign in to comment.