diff --git a/packages/workflow/src/NodeHelpers.ts b/packages/workflow/src/NodeHelpers.ts index 0e38053d3d..9c766b02a2 100644 --- a/packages/workflow/src/NodeHelpers.ts +++ b/packages/workflow/src/NodeHelpers.ts @@ -161,6 +161,20 @@ export function getContext(runExecutionData: IRunExecutionData, type: string, no * @returns {(INodeParameters | null)} */ export function getNodeParameters(nodePropertiesArray: INodeProperties[], nodeValues: INodeParameters, returnDefaults: boolean, returnNoneDisplayed: boolean, onlySimpleTypes = false, dataIsResolved = false, nodeValuesRoot?: INodeParameters, parentType?: string): INodeParameters | null { + // Get the parameter names which get used multiple times as for this + // ones we have to always check which ones get displayed and which ones not + const duplicateParameterNames: string[] = []; + const parameterNames: string[] = []; + for (const nodeProperties of nodePropertiesArray) { + if (parameterNames.includes(nodeProperties.name)) { + if (!duplicateParameterNames.includes(nodeProperties.name)) { + duplicateParameterNames.push(nodeProperties.name); + } + } else { + parameterNames.push(nodeProperties.name); + } + } + const nodeParameters: INodeParameters = {}; let nodeValuesDisplayCheck = nodeValues; @@ -188,6 +202,17 @@ export function getNodeParameters(nodePropertiesArray: INodeProperties[], nodeVa if (!['collection', 'fixedCollection'].includes(nodeProperties.type)) { // Is a simple property so can be set as it is + if (duplicateParameterNames.includes(nodeProperties.name)) { + // Parameter gets used multiple times + if (dataIsResolved !== true) { + nodeValuesDisplayCheck = getNodeParameters(nodePropertiesArray, nodeValues, true, true, true, true, nodeValuesRoot, parentType) as INodeParameters; + } + + if (!displayParameter(nodeValuesDisplayCheck, nodeProperties, nodeValuesRoot)) { + continue; + } + } + if (returnDefaults === true) { // Set also when it has the default value if (['boolean', 'number'].includes(nodeProperties.type)) { diff --git a/packages/workflow/test/NodeHelpers.test.ts b/packages/workflow/test/NodeHelpers.test.ts index 261941f53d..e381870c53 100644 --- a/packages/workflow/test/NodeHelpers.test.ts +++ b/packages/workflow/test/NodeHelpers.test.ts @@ -2212,6 +2212,95 @@ describe('Workflow', () => { }, }, }, + { + description: 'two identically named properties of which only one gets displayed with different options. No value set at all.', + input: { + nodePropertiesArray: [ + { + displayName: 'mainOption', + name: 'mainOption', + type: 'options', + options: [ + { + name: 'option1', + value: 'option1', + }, + { + name: 'option2', + value: 'option2', + }, + ], + default: 'option1', + }, + { + displayName: 'subOption', + name: 'subOption', + type: 'options', + displayOptions: { + show: { + mainOption: [ + 'option1', + ], + }, + }, + options: [ + { + name: 'option1a', + value: 'option1a', + }, + { + name: 'option1b', + value: 'option1b', + }, + ], + default: 'option1a', + }, + { + displayName: 'subOption', + name: 'subOption', + type: 'options', + displayOptions: { + show: { + mainOption: [ + 'option2', + ], + }, + }, + options: [ + { + name: 'option2a', + value: 'option2a', + }, + { + name: 'option2b', + value: 'option2b', + }, + ], + default: 'option2a', + }, + ], + nodeValues: {}, + }, + output: { + noneDisplayedFalse: { + defaultsFalse: { + }, + defaultsTrue: { + mainOption: 'option1', + subOption: 'option1a', + }, + }, + noneDisplayedTrue: { + defaultsFalse: { + }, + defaultsTrue: { + mainOption: 'option1', + subOption: 'option1a', + }, + }, + }, + }, + ];