IF node not working unless condition value is expressed in plain text

Hi there!

In this workflow I have a json that contains multiple ID’s, and each ID have a “label”. I need to get the ID from a specific “label” name. For this I am using an IF node to filter the JSON.

In this example workflow I should be able to get the “ID” by passing to the webhook query the “label” name which I need to filter, by adding ?label=bar to the webhook query. Then the IF node is set with this logic:

IF json “$label” equals “$webhook query”, then TRUE

With this I should get the following response:

image

The issue is that I am getting the “Workflow executed sucessfully” message. The IF node doesn’t recognize the value from the webhook query. Instead, if I change the value to plain text in the if condition to the label name (e.g. “foo” ), the workflow works correctly.

Here’s the workflow:

Thanks in advance!

Hey @pbdco, I just gave this a go on my end and your workflow seemed to work as expected for the first item.

When opening http://localhost:5678/webhook-test/webhook-test?label=foo, I am getting the expected response:

image

For the second case (?label=bar) it also works as expected though I imagine this might be a bit counterintuitive. The IF node would run the comparison for each item individually. Seeing it receives two items from the Convert to items node, it would now do the following looking at your expressions:

  • For the first item, it would compare the label field of the first incoming item with the query.label field of the first item of your webhook-example node.
  • For the second item, it would compare the label field of the second incoming item with the query.label field of the second item of your webhook-example node (which does not exist, which is why the condition does not result in TRUE).

From your question it seems you would like to compare the label of the second item with the query.label field of your first (and only) item of the webhook-example node. This can be achieved by prefixing your expression with $item(0) as described here. This would lead to the result you’d like to see:
image

Example Workflow

Hope this helps!

1 Like

@MutedJam thank you SO much for your quick and kind response, as usual. I really appreciate your clear explanation, now I really understand the reason of this issue that was driving me nuts! :raised_hands::sweat_smile:

Thank you!
Best regards

1 Like

Awesome, I am really happy to hear this helped!

1 Like