Bug: Edit Fields node doesn't support Optional Chaining

tested with versions: 147.3, 155.3
docker

Hi,

There seems to be a problem in the Edit Fields node, when your code contains an optional chaining operator, for instance, this code returns ‘not found’ although the data exists:

{{ (() => {
   const key_a = 'key1'
   const key_b = 'key2'
   return $('Test Data').first().json[key_a]?.[key_b] ?? 'not found'
})() }}

Note: it works fine , if you don’t use variables, but literal keys, like:

return $('Test Data').first().json['key1']?.['key2'] ?? 'not found'

It does work correctly in de code node, see workflow below.

Kind regards,

Jos

It looks like your topic is missing some important information. Could you provide the following if applicable.

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

You seem to be over-complicating the expression. This one should work

{{ $('Test Data').first().json['key1']?.['key2'] ?? 'not found' }}

That’s beside the point, I should be able to use variables. The bug report is a simplification. Please read the whole post, including the examples.

Hey @Jos_van_Uden , the Set node (“Edit Fields”) does not have the functionality of Code node and was not intended to. This is not a bug.

Hi,

It’s standard JavaScript, how is it not a bug?

Kind regards,

Jos

Expressions are not standard javascript.
You simply are not able to put whatever you want in there.
So if you want to do it like this you need to use the code node.
Or change it a bit to fit the expressions.

2 Likes

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