IF node misbehaving when using expression for both values?

Describe the issue/error/question

I am using an IF node to filter through a list of items (Gmail Labels).
I am dynamically generating the condition for this label based on previous nodes.

For example - “n8n/Day 3” may or may not exist as a Label, so we use the “Contact Day” field from Airtable appended to "n8n/Day " to check.

However, n8n always outputs all items to false.

Here is a video example of me running this node, then comparing the dynamically generated “Value 1”
against “Value 2”. The string compare tool shows both as being equal, but the IF node does not.

Additionally - if I don’t use an expression, and instead form my Value 1 manually, we get the desired output.

I have tried a variety of work arounds, including using pure Javascript to compare the values, typecasting Contact Day to a number and then the entire package to a string, using escape char "" (so n8n/Day 1)…

Driving me insane!

Please share the workflow

Share the output returned by the last node

This item is returning in the “false” branch, when it should be in the “true” branch:
{ "id": "Label_5182115527424497001", "name": "n8n/Day 1", "type": "user" }

Information on your n8n setup

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

Hi @Ilya,
welcome to the community :tada:

Sorry to hear that you are having trouble. From looking at your video, at the moment where you hover over your label with your mouse, I can see that Value 1 changes to n8n/Day instead of n8n/Day 1.

Inside your IF node expression you are mapping Contact Day from the airtable node Where Contact != Blank. I am guessing your airtable returns multiple items and by default the expression will map label item x to airtable item x, so your IF node might not compare the fields you are suspecting. We call this concept item linking.

If you’d want to use the first airtable item you could use an expression like this:
{{ $item(0).$node["Where Contact Day != Blank"].json["fields"]["Contact Day"] }}

To filter out gmail labels from a list of airtable items i would suggest using the code node with mode Run Once for All Items.

Hey Marcus,

Great shout - On quick question on Item Linking -
In my case, Airtable only returns one item.
However, it CAN return more than that.

Therefore it returns something like [{object}] rather than {object}.

My labels field returns a number of labels that doesn’t correlate to the number of Airtable items.

So does n8n do
For each item in Labels array → Match Index against Airtable fields -
So we end up with Airtable[1] through to Airtable[n] being undefined?

In any case, you’ve helped me out, and I’m sure there’s good design decision behind this concept.

For anyone Googling -
The below works for me.
I’ve also restructured my workflow slightly to be more pragmatic (pretty cool I run things async/have multiple inputs! Take that Zapier!)

const entry = $('Where Contact Day != Blank').item
return $('Get Labels').all().find(item => 
   item.json.name === 'n8n/Day ' + entry.json.fields["Contact Day"]

Again, thanks for your help Marcus.

1 Like

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