Undefined value ignoring the expression when using $node

Describe the issue/error/question

I’m trying to set a pagination loop, but when I’m trying to write the expression using the Set node value it’s returning undefined. Which is understandable for the first run. But instead of using the second conditional, it returns undefined to the entire expression.

However, when I test the same behaviour using a standard input value, not pre-defined either, it returns the second condition correctly.

It’s easier seen than explained.
image

Expression code testing here

{{ $json.year }}
{{ $json.year || 2021 }}

{{ $node["Year pagination"].json["year"] }}
{{ $node["Year pagination"].json["year"] || 2021 }}

Desired result

In the first run, even when the value hasn’t been defined yet
{{ $node["Year pagination"].json["year"] || 2021 }} → 2021

What is the error message (if any)?

undefined

Please share the workflow

I’m pasting the entire workflow just for reference, but the question relates only to the HTTP and “Year pagination” nodes.

Hi @Chaoscontrol, I am sorry you’re having trouble. Unfortunately your workflow seems to require credentials for a 3rd party service, so I won’t be able to use it.

Short-circuit evaluation in works in principle, also in loops. Here’s a quick example showing the idea:

When executing the workflow, you can see how for the fourth loop the incoming country value is null, but the expression still overwrites it with "none":

Perhaps you can share a workflow including mock data and not requiring 3rd party credentials using which your problem can be reproduced? Also it’d be great if you could confirm the exact version of n8n you have in use.

1 Like

No worries. I already said the entire flow was just to give context, but the issue is not related to the outputs or format of data. The issue only related to referencing other node values that hadn’t been previously defined.

I honestly think there’s a bug in there, but requires a bit of debugging to find the exact case scenario.

I ended up going away from this solution. I’ll leave the flow here in case it helps someone else.

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