Expression parameter not returning actual result of the expression

Hello, I am working on my first custom node (declarative style) and noticed that expressions in input parameters don’t evaluate correctly (salutation and lastName). Object created in my application will have the literal value ={{$json[“salutation”]}} for salutation and ={{$json[“lastName”]}} for lastName and not the actual result of the expressions, which would be: “Mr.”, “Johnson”.

Workflow code:

{
  "nodes": [
    {
      "parameters": {
        "operation": "createPersonAsCustomer",
        "personDetailsUI": {
          "personDetails": {
            "salutation": "={{$json[\"salutation\"]}}",
            "firstName": "Fred",
            "lastName": "={{$json[\"lastName\"]}}"
          }
        },
        "emailAddressesUI": {
          "emailAddresses": {
            "business": "[email protected]"
          }
        },
        "phoneNumbersUI": {
          "phoneNumbers": {
            "mobile": "0923212132",
            "private": "0923212132"
          }
        }
      },
    }
  ]

Custom node request:

{
						name: 'Create Person - Customer',
						value: 'createPersonAsCustomer',
						action: 'Create person with customer role',
						description: 'Create person with customer role',
						routing: {
							request: {
								method: 'POST',
								url: '/v1/contacts',
								body: {
									version: 0,
									roles: {
										customer: {},
									},
									person: '={{$parameter.personDetailsUI.personDetails}}',
									addresses: {
										billing: '={{$parameter.billingUI.billing}}',
									},
									emailAddresses: {
										business: ['={{$parameter.emailAddressesUI.emailAddresses.business}}'],
									},
									phoneNumbers: {
										mobile: ['={{$parameter.phoneNumbersUI.phoneNumbers.mobile}}'],
										private: ['={{$parameter.phoneNumbersUI.phoneNumbers.private}}'],
									},
								},
							},
						},
					}

Custom node fields:

{
				displayName: 'Person Details',
				name: 'personDetailsUI',
				placeholder: 'Add Person Details',
				type: 'fixedCollection',
				default: {},
				typeOptions: {
					multipleValues: false,
				},
				description: 'Add Person Details',
				options: [
					{
						name: 'personDetails',
						displayName: 'Person Details',
						values: [
							{
								displayName: 'Salutation',
								name: 'salutation',
								type: 'string',
								default: '',
								description: 'Type in salutation for person',
								hint: 'Herr or Frau',
							},
							{
								displayName: 'First Name',
								name: 'firstName',
								type: 'string',
								default: '',
								description: 'Type in first name for person',
							},
							{
								displayName: 'Last Name',
								name: 'lastName',
								required: true,
								type: 'string',
								default: '',
								description: 'Type in last name for person',
							},
						],
					},
				],
				displayOptions: {
					show: {
						resource: ['contactsEndpoint'],
						operation: [
							'createPersonAsCustomer',
							'createPersonAsCustomerAndVendor',
							'createPersonAsVendor',
					],
					},
				},
			},

Thank you!

Hi @alexnemes, welcome to the community :tada:

Perhaps our resident node builder @marcus can take a look into this?

1 Like

Hi @alexnemes,
when you add the expression in n8n’s editor UI, do you see an expression preview like this?

image

Is your custom node code publicly hosted somewhere so that I can have a look?

Hi @marcus thanks for the reply.

I do see an expression preview:

And here is the contact created in my application:

image

The custom node is public:

Thank you and let me know if you need more information.

Hey Alex,
I looked into your issue and it seems like expressions aren’t correctly evaluated when setting the body in your operations. We will have to investigate further to fix the issue, until then you could do this:

Using the routing option on individual parameters will correctly resolve expressions.

Hey @marcus thanks for this alternative! It works! Will update the rest of the parameters.

1 Like

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