IF node is does not filter JSON if Value 2 input is an Expression

I’m trying to get the record “id” by filtering the list of records in a database using a reference number from a newly submitted form in my app. I tried using the “IF” function, but it’s not working.

Step 1:
I get a trigger from a webhook containing the information from a newly submitted form in my app.

Step 2:
I send HTTP GET to obtain the list of all records of the form submitted in my database in JSON format.

Step 3:
I clean the unnecessary headers and stuff using the “Set” node.

Step 4:
I split the items of my JSON using the “Function” node.

Step 5: (HERE IS THE PROBLEM)
I’m trying to filter the records using “ReferenceID” from the “Split into items” node in Value 1 in Expression. Then set the Value 2 in Expression to get the “ReferenceID” from the webhook.

You can see that there is no result in True Branch :point_down::point_down::point_down:

But when I remove the Expression in Value 2 and input just the ReferenceID.

Boom! Filter worked.

**I need to filter ReferenceID to get the record “id” which the webhook doesn’t have and I need it.

Hi @ruel.lago , try this instead, I set the top value on the IF node to parse the integer. I found the result on this post. :

Hi @djangelic,

Thank you for trying, appreciate it. But it didn’t solve the problem :smiling_face_with_tear: I Already took note of some of the threads here like https://community.n8n.io/t/if-filter-does-not-work-with-hubspot-trigger-node/3431/3

** Same problem. If I remove the Expression in Value 2 and use just plain numbers, it works :smiley:

1 Like

Hey @ruel.lago, the latest example you have shared wouldn’t work because your expression doesn’t return anything (it refers to a Webhook node which isn’t present in your workflow).

Though I think I might have an idea what’s going on here. Your “Split into Items1” node (btw, this could also be an Item Lists node splitting out your items - that way you don’t have to write code) returns 16 items, but a webhook would typically have a single item only.

Now what would happen on your IF node is that for the first item arriving on your IF node the expression will read the first item on your webhook node. This probably works. For the second item, your expression will read the second item on your webhook node which is most likely what fails here.

However, if you add $item(0). to your expression like {{parseInt($item(0).$node["Webhook"].json["body"]["ReferenceID"])}}, the comparison should work as expected:

2 Likes

Hi @MutedJam,

Hope you’re doing great today. Thank you for sharing the Item Lists node, didn’t realize I’m doing it a hard way :sweat_smile: I applied this on my workflow instead of the Function node.

By adding $item(0). the IF node successfully filtered the Value 2 like a charm :sunglasses:

Been working on this for 3 days already and I finally decided to get help on this community which I find very active. Thank you!

1 Like

Awesome, so glad to hear that was it! Reach out anytime in case something doesn’t work as expected :slight_smile:

1 Like

I have the same problem when I use a string, how do I solve it?

Hey @Cristobal_Moya,

Would you be able to open a new thread and include a bit more information, I ran the workflow you provided and I get some data to true and some to false so it is hard to see what the problem is that you are having.