I have setup an IF node to perform a simple check and the logic is not behaving as expected. I am simply comparing 2 values to decide whether or not to execute downstream nodes. If the input value is 0 then the “true” branch should qualify. If the input value is any other value than 0 then the “false” branch should qualify. However, upon inspection of the execution this morning, the input value was “0” but get the node still resolved to “false”. The workflow completed successfully but it sent out a notification to a user telling them they had 0 actions to take. I want to prevent notifications from going out when nothing needs to be done.
Hi @chadgriff1, I don’t have access to the data you are referencing in your workflow, but I suspect what’s happening here is this that the number and order of items between your “Adjustment Counts” node and your “Chk Os Bldg Adj Cnt” node changes.
Now your expression {{ $node["Adjustment Counts"].json["osBldgCnt"] }} would
for the first item on the “Chk Os Bldg Adj Cnt” node look up the first item on the “Adjustment Counts” node
for the second item on the “Chk Os Bldg Adj Cnt” node look up the second item on the “Adjustment Counts” node
etc.
While the first comparison might still work, the second one would fail if your SQL query only returns only a single row.
In such cases you would need another expression accounting for the different data structure. Looking at Built in methods and variables reference | n8n Docs a suitable one in this case could be {{ $("Adjustment Counts").first().json["osBldgCnt"] }}. This would always read the first (and only) item from the “Adjustment Counts” node.
@MutedJam Thanks for your response. I can now see I should have included more detail in my post.
The query in the “Adjustment Counts” node will always return 2 records as follows:
OSBLDGCNT 14
NONOSBLDGCNT 0
The upper IF node in my workflow compares the OSBLDGCNT record against a static value of 0 (zero) while the lower IF node compares the NONOSBLDGCNT records against a static value of 0 (zero). In the execution screenshot I provided of the “Chk NonOS Bldg Adj Cnt” you can see where the value of 0 = 0 is resolving to false. Attached is a copy of the execution of the “Adjustment Counts” node.
So I think the example provided {{ $("Adjustment Counts").first().json["osBldgCnt"] }} should work fine. Did you have a chance to test this approach in your workflow?
The expected behavior is that the upper path for “osbldg” should have sent out a message by following the “false” branch of the IF node (which it did). However, the lower “nonosbldg” branch sent out messages as well by following the “false” branch vs. resolving to the “true” branch by comparing 0 = 0.
Here is how I had both IF nodes configured…
In the nonosbldg IF node, I tested with both Combine options (i.e. ALL and ANY) and it resolved to “false” in both configurations.
Do I have to do anything special with “Value 2” in the IF node by chance?