How to display a parameter over some non-parameter based condition

Hi,

I’m trying to show a parameter only if some ‘x’ field is available in the response when the first parameter is loaded. I know we can apply condition via displayOptions -> show, but the key and values needs to be the name of some other parameter, otherwise it throws following error Could not resolve parameter depenencies. Max itterations got reached. But in my case the condition I want to display the parameter on, is not the name of the another param, it’s some field which will be available according to the selected value.

my goal is to display List of DB paramter only if the the selected field’s value carry the field ds_connector_type as `cloud from the first parameter, something like this:

		{
			displayName: 'DataSource Name',
			name: 'datasource',
			type: 'options',
			typeOptions: {
				loadOptionsMethod: 'getDatasources',
			},
			required: true,
			default: '',
			description: ''
		},
		{
			displayName: ‘List of DB',
			name: 'databases',
			type: 'options',
			typeOptions: {
				loadOptionsDependsOn: ['datasource'],
				loadOptionsMethod: 'getDatabases',
			},
			displayOptions: {
				show: {
					ds_connector_type: [
						'cloud'
					],
				},
			},
			required: false,
			default: '',
			description: 'Database names configured on Privaci Datasources page.'
		},

The method getDatasources will make an api call and load the names in the dropdown, if the selected field’s value carry ds_connector_type as cloud, only then I want to display the parameter ‘List of DB’ else not.
Code for getDatasources :

        async getDatasources(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
            const returnData: INodePropertyOptions[] = [];
            const res = await getDatasourceList.call(this);
            
            for (const item of res) {
                const dsObj = {

                    id: item.id,
                    name: item.name,
                    ds_connector_type: item.ds_connector_type,
                    onprem_connector: item.onprem_connector,
                    cloud_connector: item.cloud_connector,
                };
                returnData.push({
                    name: item.name,
                    value: JSON.stringify(dsObj),
                });
        
            }           
            return returnData;
        },

Kindly let me know if what I’m trying to achieve is even possible ? if yes then how can I achieve this ?
Thank you.

Hey @Shahtaj_Khalid, I am not sure about this one tbh, but have asked the team for help with this. Let’s see if someone has a more helpful answer here :slight_smile:

One approach:

{
	displayName: 'Has Cloud Connector',
	name: 'hasCloudConnector',
	type: 'hidden',
	default: '={{ JSON.parse($parameter["&datasource"]).ds_connector_type === "cloud" }}',
},
{
	displayName: 'List of DB',
	name: 'databases',
	type: 'options',
	default: '',
	required: false,
	displayOptions: {
		show: {
			hasCloudConnector: [
				true
			],
		},
	},
}

Untested, might need adjusting.

1 Like

I tried this, but it’s not working, seems like the show condition is unable the read the value from when the value is set via expression.

made the field Has Cloud Connector visible for testing.
this is what I tried :

  	{
  		displayName: 'Has Cloud Connector',
  		name: 'hasCloudConnector',
  		type: 'boolean',
  		default: '={{JSON.parse($parameter["datasource"]).ds_connector_type === "cloud"}}'
  	{
  		displayName: 'Connect to Database',
  		name: 'databases',
  		type: 'options',
  		typeOptions: {
  			loadOptionsDependsOn: ['hasCloudConnector', 'datasource'],
  			loadOptionsMethod: 'getDatabases',
  		},
  		displayOptions: {
  			show: {
  				hasCloudConnector: [
  					'true', 
  					true
  				],
  			},
  		},

When Running via above code:

and when I remove the expression and set it to true manually, I’m able to see the parameter:
Screenshot 2022-02-10 at 1.14.01 PM

Did you check the expression in the expression editor to see what it is evaluating to?

hasCloudConnector might be resolving the expression before datasource has loaded its options.

hasCloudConnector is evaluating the value correctly and is switching the value to true/false properly when I select different option from Datasource name :

Confirmed internally that load options were never meant to store JSON, which is likely causing display options to fail to toggle, even if the expression evaluates correctly.

Will leave it to @RicardoE105 to suggest a workaround.

Sure, thanks. I’m really looking forward to hear back on this.