mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-26 21:19:43 -08:00
76 lines
1.7 KiB
TypeScript
76 lines
1.7 KiB
TypeScript
import { OptionsWithUri } from 'request';
|
|
|
|
import { IExecuteFunctions } from 'n8n-core';
|
|
import {
|
|
ILoadOptionsFunctions,
|
|
INodeExecutionData,
|
|
INodePropertyOptions,
|
|
INodeType,
|
|
INodeTypeDescription,
|
|
} from 'n8n-workflow';
|
|
|
|
|
|
export class ExecuteWorkflow implements INodeType {
|
|
description: INodeTypeDescription = {
|
|
displayName: 'Execute Workflow',
|
|
name: 'executeWorkflow',
|
|
icon: 'fa:network-wired',
|
|
group: ['transform'],
|
|
version: 1,
|
|
subtitle: '={{"Workflow: " + $parameter["workflowId"]}}',
|
|
description: 'Execute another workflow',
|
|
defaults: {
|
|
name: 'Execute Workflow',
|
|
color: '#ff6d5a',
|
|
},
|
|
inputs: ['main'],
|
|
outputs: ['main'],
|
|
properties: [
|
|
{
|
|
displayName: 'Workflow',
|
|
name: 'workflowId',
|
|
type: 'options',
|
|
typeOptions: {
|
|
loadOptionsMethod: 'getWorkflows',
|
|
},
|
|
default: '',
|
|
required: true,
|
|
description: 'The workflow to execute.',
|
|
},
|
|
]
|
|
};
|
|
|
|
methods = {
|
|
loadOptions: {
|
|
async getWorkflows(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
const options: OptionsWithUri = {
|
|
method: 'GET',
|
|
uri: this.getRestApiUrl() + '/workflows',
|
|
json: true
|
|
};
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
const responseData = await this.helpers.request!(options);
|
|
for (const workflowData of responseData.data) {
|
|
returnData.push({
|
|
name: workflowData.name,
|
|
value: workflowData.id,
|
|
});
|
|
}
|
|
|
|
return returnData;
|
|
}
|
|
},
|
|
};
|
|
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
const items = this.getInputData();
|
|
const workflowId = this.getNodeParameter('workflowId', 0) as string;
|
|
const receivedData = await this.executeWorkflow(workflowId, items);
|
|
|
|
return receivedData;
|
|
}
|
|
}
|