Repeat the value of a single item expression when comparing to a list of items in an IF statement

Describe the issue/error/question

I’m sure I am not explaining this very well but here goes:

I have a value that is outputted by a SET node (let’s call it ‘Red’) and I want to compare it to an Item List of colors ‘Blue, Green, Yellow, Purple, etc.’

For each item in the list, IF any of these items matches ‘Red’ then I want the IF node to output the result under the True column.

The problem is, I can only get this behaviour using a hard coded value IE if I enter ‘Red’ as a string.

If I try to use ‘Red’ as an expression from the SET node, all items return False.

It seems the only way I can get it to work the way I want is to use a Merge node + multiplex to combine the single value of the SET node i.e. ‘Red’ and add as another column / set of data to each of the items from the Item List node.

Is there a way to ‘persist’ a single expression value so that it gets repeated when comparing to a list of items coming from another expression value in an IF statement?

What is the error message (if any)?

Please share the workflow

Sorry I don’t have a good working example because my workflow is hooked up to so many data sources.

Share the output returned by the last node

Information on your n8n setup

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

I just discovered that I can use the Merge Node as a standalone to accomplish the same task.

Basically “if field A matches field B, keep the one that matches”.

TIL

1 Like

Glad to hear you figured it out already. Thanks for sharing your approach!

1 Like