From 1999f4b066784cc1dd6a962f51d7c11641577a8b Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Wed, 8 Jun 2022 18:16:55 +0200 Subject: [PATCH] fix(core): Properly resolve expressions in declarative node design --- packages/workflow/src/RoutingNode.ts | 17 ++++++- packages/workflow/test/RoutingNode.test.ts | 56 ++++++++++++++++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/packages/workflow/src/RoutingNode.ts b/packages/workflow/src/RoutingNode.ts index 34ae2ba102..525ee062a8 100644 --- a/packages/workflow/src/RoutingNode.ts +++ b/packages/workflow/src/RoutingNode.ts @@ -564,7 +564,10 @@ export class RoutingNode { additionalKeys?: IWorkflowDataProxyAdditionalKeys, returnObjectAsString = false, ): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | string { - if (typeof parameterValue === 'string' && parameterValue.charAt(0) === '=') { + if ( + typeof parameterValue === 'object' || + (typeof parameterValue === 'string' && parameterValue.charAt(0) === '=') + ) { return this.workflow.expression.getParameterValue( parameterValue, this.runExecutionData ?? null, @@ -820,8 +823,18 @@ export class RoutingNode { value = [value]; } + // Resolve expressions + value = this.getParameterValue( + value as INodeParameters[], + itemIndex, + runIndex, + executeSingleFunctions.getExecuteData(), + { ...additionalKeys }, + false, + ) as INodeParameters[]; + const loopBasePath = `${basePath}${propertyOptions.name}`; - for (let i = 0; i < (value as INodeParameters[]).length; i++) { + for (let i = 0; i < value.length; i++) { for (const option of propertyOptions.values) { const tempOptions = this.getRequestOptionsFromParameters( executeSingleFunctions, diff --git a/packages/workflow/test/RoutingNode.test.ts b/packages/workflow/test/RoutingNode.test.ts index 439ebaa28f..aa1371baa8 100644 --- a/packages/workflow/test/RoutingNode.test.ts +++ b/packages/workflow/test/RoutingNode.test.ts @@ -961,6 +961,7 @@ describe('RoutingNode', () => { input: { node: { parameters: { + value1: '={{"test"}}', multipleFields: { value1: 'v1', value2: 'v2', @@ -998,11 +999,25 @@ describe('RoutingNode', () => { }, ], }, + customPropertiesMultiExp: { + property0: [ + { + name: '={{$parameter["value1"]}}N', + value: '={{$parameter["value1"]}}V', + }, + ], + }, }, }, }, nodeType: { properties: [ + { + displayName: 'Value 1', + name: 'value1', + type: 'string', + default: '', + }, { displayName: 'Multiple Fields', name: 'multipleFields', @@ -1285,6 +1300,46 @@ describe('RoutingNode', () => { }, ], }, + // Test fixed collection: multipleValues=true with expression which references an expression + { + displayName: 'Custom Properties (multi)', + name: 'customPropertiesMultiExp', + placeholder: 'Add Custom Property', + type: 'fixedCollection', + typeOptions: { + multipleValues: true, + }, + default: {}, + options: [ + { + name: 'property0', + displayName: 'Property0', + values: [ + // To set: { name0: 'value0', name1: 'value1' } + { + displayName: 'Property Name', + name: 'name', + type: 'string', + default: '', + description: 'Name of the property to set.', + }, + { + displayName: 'Property Value', + name: 'value', + type: 'string', + default: '', + routing: { + send: { + property: '={{$parent.name}}', + type: 'body', + }, + }, + description: 'Value of the property to set.', + }, + ], + }, + ], + }, ], }, ], @@ -1324,6 +1379,7 @@ describe('RoutingNode', () => { value: 'cM1Value2', }, ], + testN: 'testV', }, method: 'POST', headers: {