populate workflow Inputs

This commit is contained in:
Ivan Atanasov 2024-11-28 18:59:01 +01:00
parent 0a924e0dd3
commit 0ffc72a8a3
No known key found for this signature in database
2 changed files with 28 additions and 8 deletions

View file

@ -199,7 +199,7 @@ export class ExecuteWorkflow implements INodeType {
},
required: true,
typeOptions: {
loadOptionsDependsOn: ['workflowId.value'],
loadOptionsDependsOn: ['workflowId.value', 'workflowJson'],
resourceMapper: {
resourceMapperMethod: 'getWorkflowInputs',
mode: 'add',
@ -214,11 +214,11 @@ export class ExecuteWorkflow implements INodeType {
},
displayOptions: {
show: {
source: ['database'],
'@version': [{ _cnd: { gte: 1.2 } }],
},
hide: {
workflowId: [''],
workflowJson: ['\n\n\n'],
},
},
},

View file

@ -1,22 +1,42 @@
import type {
FieldType,
ILoadOptionsFunctions,
ResourceMapperField,
ResourceMapperFields,
} from 'n8n-workflow';
import { getWorkflowInfo } from '../GenericFunctions';
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 source = this.getNodeParameter('source', 0) as string;
const fields: ResourceMapperField[] = workflowInputs.map((col) => ({
id: col,
displayName: col,
const executeWorkflowInfo = await getWorkflowInfo.call(this, source);
if (executeWorkflowInfo.code === undefined) {
// executeWorkflowInfo.code = await getWorkflowById.call(this, executeWorkflowInfo.id as string);
}
const workflowInputs = (
Array.isArray(
executeWorkflowInfo.code?.nodes.find(
(node) => node.type === 'n8n-nodes-base.executeWorkflowTrigger',
)?.parameters.workflowInputs,
)
? executeWorkflowInfo.code?.nodes.find(
(node) => node.type === 'n8n-nodes-base.executeWorkflowTrigger',
)?.parameters.workflowInputs
: []
) as Array<{ name: string; type: FieldType }>;
const fields: ResourceMapperField[] = workflowInputs.map((currentWorkflowInput) => ({
id: currentWorkflowInput.name,
displayName: currentWorkflowInput.name,
required: false,
defaultMatch: true,
display: true,
type: 'number',
type: currentWorkflowInput.type || 'string',
canBeUsedToMatch: true,
}));