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
n8n
September 19, 2024, 11:16am
2
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:
ihortom
September 19, 2024, 6:31pm
3
Jos_van_Uden:
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
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.
ihortom
September 19, 2024, 8:26pm
5
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
BramKn
September 21, 2024, 7:27pm
7
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
system
Closed
September 28, 2024, 7:27pm
8
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.