How to fill a multiOptions field with an expression

Describe the question

The Freshworks CRM Node offers nice UI support. For the “Contact” → “Create” action it offers an additional field called “sales_accounts” which is implemented as a multiOption field with an attached loadOptionsMethod.
I do have the ID of one sales_account that I want the contact to create within from a previous node. But the n8n editor always fails the validation of the field input. I tried an array of string, an array of int, an object, an array of objects …

How to set that multiOption value dynamically?

			{
				displayName: 'Sales Accounts',
				name: 'sales_accounts',
				type: 'multiOptions',
				default: [],
				typeOptions: {
					loadOptionsMethod: 'getAccounts',
				},
				description: 'Accounts which contact belongs to',
			}

Please share the workflow

Share the output returned by the last node

"additionalFields.sales_accounts.map is not a function"

Information on your n8n setup

  • n8n version: 0.172.0
  • Database you’re using (default: SQLite): SQLite (localhost DEV)
  • Running n8n with the execution process [own(default), main]: npm run dev
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: npm

Thank you very much :slight_smile:

Hey @JanTh,

That is a good question I have never tried, @RicardoE105 may have some thoughts.

You have to return an array. So if you want to set the values “a” and “b” you would have to set the expression:

{{ [ "a","b"] }}
2 Likes

Thanks Jan!
I believe I simply missed the {{ }} and such always used strings when I believed to use structured data … ouch … I will be able to confirm this at the start of next week.

@jan
I was finally able to retest this and your suggestion is not working:

When I select any one of the prepopulated values and then add an expression, the value is simply converted into a simple string. The Expression contains this: <valid-id>.

Where <valid-id> is the ID string of the selected entity.

As you suggested, I changed the expression to this:
{{ ["<valid-id>"] }} => [Array: ["<valid-id>"]]
and also tried this:
{{ [<valid-id>] }} => [Array: [<valid-id>]]

Both lead to the same validation error in the UI:

The value “[Array: [<valid-id>]]” is not supported!

Any further suggestions?