Multiple Questions regarding building Nodes

Hey everyone,

I’m currently building a node with multiple functions (currently around 100).

I ran across a problems that I don’t know how to solve:

Many of my functions require data inputs as Arrays.
Those arrays can be:

  • regular string arrays
  • json arrays with a known structure. E.g.:
    {
       "name": string,
       "age": number
    }
  • json arrays with a unknown structure

What is the best my to solve all 3 cases?

In case of string arrays i went with the following code:

{
		displayName: 'My field label',
		description: 'My field description.',
		name: 'myFieldName',
		required: false,
		type: 'string',
		default: [],
		typeOptions: {
			multipleValues: true,
		},
		displayOptions: {
			....
		},
	},

But with that its not possible to pass a full array via an expression for this field. Only each individual string can be an expression. See the following screenshot.
SCR-20230510-fgd

In case 2 (json array with known structure) I went with a field of type “fixedCollection”. That ends in the same problem as for the string array where i can’t pass a full array for the field.

In case 3 (json array of unknown structure) I want with a field of type “json”. If i now set:

{
...
typeOptions: {
   multipleValues:true
}
}

I would end up with the same problem that I have for case 1 and 2.

So the question:
Is it possible to pass a expression as a value for the whole array field and on the other hand make it also possible allow expressions for individual spots in the array?

I hope someone can help.

Johannes

Information on your n8n setup

  • n8n version: latest
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): locally n8n start
  • Operating system: Mac OS

Hi @JohannesHspx,
I gave it a quick go and here is one proposal.

Node parameter Tags with multiple values

{
	displayName: 'Tags',
	name: 'tags',
	type: 'string',
	default: [],
	typeOptions: {
		multipleValues: true,
	}
},

Inside the execute function

const tags = (this.getNodeParameter('tags', itemIndex, []) as []).flat();
console.log(tags);

This will result in tags ["a", "b", "c"] for the following inputs

image

image

The third one using an expression will resolve to [["a", "b," "c"]] so flat() will make it to ["a", "b", "c"].

1 Like

Hi,

thanks for your answer.

I’m still a little confused.
In your first screenshot multipleValues is set to true but in your second screenshot its set to false right?

Is it not possible to allow both?

So have a button to add another value and the option to use an expression for the wohle array as seen in your second screenshot?
You can do that in Make (see screenshot) that is not possible in n8n?

Hi,
both screenshots are using the same multiple values parameters.

Your make example would be using a fixed collection. We also often introduce a “mode” parameter to support different input modes. For example the HttpRequest node shows/hides different node parameters depending if you select either Using Fields Below or Using JSON.

image

1 Like

That helped me a lot. Thanks.

Will reply here if any other questions occur :slight_smile:

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.