add workflow inputs parameters

This commit is contained in:
Ivan Atanasov 2024-11-25 23:33:43 +01:00
parent 7012d9bb9c
commit 6f66faaabd
No known key found for this signature in database
2 changed files with 65 additions and 0 deletions

View file

@ -8,6 +8,7 @@ import type {
} from 'n8n-workflow';
import { getWorkflowInfo } from './GenericFunctions';
import { getWorkflowInputs } from './methods/resourceMapping';
import { generatePairedItemData } from '../../utils/utilities';
export class ExecuteWorkflow implements INodeType {
@ -187,6 +188,40 @@ export class ExecuteWorkflow implements INodeType {
default: '',
displayOptions: { show: { '@version': [{ _cnd: { lte: 1.1 } }] } },
},
{
displayName: 'Workflow Inputs',
name: 'workflowInputs',
type: 'resourceMapper',
noDataExpression: true,
default: {
mappingMode: 'defineBelow',
value: null,
},
required: true,
typeOptions: {
loadOptionsDependsOn: ['workflowId.value'],
resourceMapper: {
resourceMapperMethod: 'getWorkflowInputs',
mode: 'upsert',
fieldWords: {
singular: 'workflow input',
plural: 'workflow inputs',
},
addAllFields: true,
multiKeyMatch: false,
supportAutoMap: false,
},
},
displayOptions: {
show: {
source: ['database'],
'@version': [{ _cnd: { gte: 1.2 } }],
},
hide: {
workflowId: [''],
},
},
},
{
displayName: 'Mode',
name: 'mode',
@ -228,6 +263,12 @@ export class ExecuteWorkflow implements INodeType {
],
};
methods = {
resourceMapping: {
getWorkflowInputs,
},
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const source = this.getNodeParameter('source', 0) as string;
const mode = this.getNodeParameter('mode', 0, false) as string;

View file

@ -0,0 +1,24 @@
import type {
ILoadOptionsFunctions,
ResourceMapperField,
ResourceMapperFields,
} from 'n8n-workflow';
export async function getWorkflowInputs(
this: ILoadOptionsFunctions,
): Promise<ResourceMapperFields> {
// TODO: take the columns from the workflow input
const workflowInputs = ['uid', 'Test Field 2', 'Test Field 3'];
const fields: ResourceMapperField[] = workflowInputs.map((col) => ({
id: col,
displayName: col,
required: false,
defaultMatch: col === 'id',
display: true,
type: 'string',
canBeUsedToMatch: true,
}));
return { fields };
}