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

View file

@ -1,22 +1,42 @@
import type { import type {
FieldType,
ILoadOptionsFunctions, ILoadOptionsFunctions,
ResourceMapperField, ResourceMapperField,
ResourceMapperFields, ResourceMapperFields,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { getWorkflowInfo } from '../GenericFunctions';
export async function getWorkflowInputs( export async function getWorkflowInputs(
this: ILoadOptionsFunctions, this: ILoadOptionsFunctions,
): Promise<ResourceMapperFields> { ): Promise<ResourceMapperFields> {
// TODO: take the columns from the workflow input const source = this.getNodeParameter('source', 0) as string;
const workflowInputs = ['uid', 'Test Field 2', 'Test Field 3'];
const fields: ResourceMapperField[] = workflowInputs.map((col) => ({ const executeWorkflowInfo = await getWorkflowInfo.call(this, source);
id: col,
displayName: col, 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, required: false,
defaultMatch: true, defaultMatch: true,
display: true, display: true,
type: 'number', type: currentWorkflowInput.type || 'string',
canBeUsedToMatch: true, canBeUsedToMatch: true,
})); }));