[Bug] If Node output false with Send Email node problem!

There is a bug when using If Node with Send Email node, I have Google Sheets like this pic
image
Link: https://docs.google.com/spreadsheets/d/1FFMzZWLpLUkcSLHENlzZL4i2gCKS9ycVqqqeRwbsbDo/edit#gid=0

I setup a simple Workflow with If Node and Send Email like this

    {
  "nodes": [
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$node[\"Google Sheets\"].json[\"updated\"]}}",
              "value2": "1"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        640,
        300
      ]
    },
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "sheetId": "1FFMzZWLpLUkcSLHENlzZL4i2gCKS9ycVqqqeRwbsbDo",
        "range": "A:C",
        "options": {}
      },
      "name": "Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        440,
        300
      ],
      "credentials": {
        "googleSheetsOAuth2Api": "Google Sheets OAuth2 API detailhelp"
      }
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$node[\"Google Sheets\"].json[\"updated\"]}}",
              "value2": "1"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        640,
        300
      ]
    },
    {
      "parameters": {
        "fromEmail": "[email protected]",
        "toEmail": "={{$node[\"IF\"].json[\"email\"]}}",
        "subject": "Send email test true if",
        "text": "Send email True output is ok!",
        "options": {}
      },
      "name": "Send Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 1,
      "position": [
        850,
        560
      ],
      "credentials": {
        "smtp": "SMTP [email protected]"
      }
    },
    {
      "parameters": {
        "fromEmail": "[email protected]",
        "toEmail": "={{$node[\"IF\"].json[\"email\"]}}",
        "subject": "Send email test false if",
        "text": "Not send false, it only send number false by order, not result!",
        "options": {}
      },
      "name": "Send Email1",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 1,
      "position": [
        820,
        150
      ],
      "credentials": {
        "smtp": "SMTP [email protected]"
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "operation": "append",
        "sheetId": "1FFMzZWLpLUkcSLHENlzZL4i2gCKS9ycVqqqeRwbsbDo",
        "range": "Sheet2!A:C",
        "options": {}
      },
      "name": "Google Sheets1",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        850,
        390
      ],
      "credentials": {
        "googleSheetsOAuth2Api": "Google Sheets OAuth2 API detailhelp"
      }
    }
  ],
  "connections": {
    "IF": {
      "main": [
        [
          {
            "node": "Send Email1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Email",
            "type": "main",
            "index": 0
          },
          {
            "node": "Google Sheets1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Start": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

My If condition is If updated = 1, I want to send If Node output false but instead of sending email with If Node output false, Send Email node will send the number emails in list by order, You can check by use above code. Please check this!

For more clearly, I’ve made a video to describe, hope you guys understand https://youtu.be/5l3FW-HaAAg

Without having tested anything there seems to be something messed up in the json. For some reason the main connection is connected to null.

So, Is there any my configure wrong?

Put your code in ```(Before and after) to have it formatted correctly for people to copy here and test it :slight_smile:

1 Like

The last two fields in the spreadsheet do not have a value. Perhaps that is the issue.

I’m not sure what he wants to do

If Updated = 1 it needs to send an email
and if it’s not then what?

(I’m not completely sure what would be going wrong)

Sorry for my bad explain, I’ve updated picture and code for more clearly! I have 2 group, updated = 1 and not = 1. I want to send email to 2 groups. I’ve add Google Sheets append for more clear. Output to Sheet2 with Google Sheets append is ok with If node output field, but Send Email node is not!

For more clearly, I’ve made a video to describe, hope you guys understand https://youtu.be/5l3FW-HaAAg

I’ve noticed that sometimes False values do not get passes along properly, to fix it in my case i do this, it’s probably not the ultimate solution but it works:

{
  "nodes": [
    {
      "parameters": {
        "sheetId": "1FFMzZWLpLUkcSLHENlzZL4i2gCKS9ycVqqqeRwbsbDo",
        "range": "A:C",
        "options": {}
      },
      "name": "Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        680,
        330
      ],
      "credentials": {
        "googleApi": "Personal Account"
      }
    },
    {
      "parameters": {
        "fromEmail": "[email protected]",
        "toEmail": "={{$node[\"Merge\"].json[\"email\"]}}",
        "subject": "Send email test true if",
        "text": "Send email True output is ok!",
        "options": {}
      },
      "name": "Send Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 1,
      "position": [
        1150,
        500
      ],
      "credentials": {
        "smtp": "SMTP Mail (MailTrap)"
      }
    },
    {
      "parameters": {
        "fromEmail": "[email protected]",
        "toEmail": "={{$node[\"IF1\"].json[\"email\"]}}",
        "subject": "Send email test false if",
        "text": "Not send false, it only send number false by order, not result!",
        "options": {}
      },
      "name": "Send Email1",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 1,
      "position": [
        1090,
        250
      ],
      "credentials": {
        "smtp": "SMTP Mail (MailTrap)"
      }
    },
    {
      "parameters": {
        "operation": "append",
        "sheetId": "1FFMzZWLpLUkcSLHENlzZL4i2gCKS9ycVqqqeRwbsbDo",
        "range": "Sheet2!A:C",
        "options": {}
      },
      "name": "Google Sheets1",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        1300,
        400
      ],
      "credentials": {
        "googleApi": "Personal Account"
      }
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$node[\"Google Sheets\"].json[\"updated\"]}}",
              "value2": "1"
            }
          ]
        }
      },
      "name": "IF1",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        880,
        330
      ]
    },
    {
      "parameters": {
        "mode": "passThrough"
      },
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        1000,
        500
      ]
    }
  ],
  "connections": {
    "Google Sheets": {
      "main": [
        [
          {
            "node": "IF1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF1": {
      "main": [
        [
          {
            "node": "Send Email1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Google Sheets1",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Send Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

1 Like

Thanks for your guest solution, hope @jan @RicardoE105 will have the permanent solution for this!

Atleast you can test out the rest for now :slight_smile:

1 Like

@huuich, maybe trying the Switch node rather the IF node delivery the desired (multistep) result? However, I am new to n8n and might be totally mislead.

1 Like

Yeah, Your solution is ok! I’ve use your code to test.

You can try, Switch node has same problem like IF node

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "sheetId": "1FFMzZWLpLUkcSLHENlzZL4i2gCKS9ycVqqqeRwbsbDo",
        "range": "A:C",
        "options": {}
      },
      "name": "Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        440,
        300
      ],
      "credentials": {
        "googleSheetsOAuth2Api": "Google Sheets OAuth2 API detailhelp"
      }
    },
    {
      "parameters": {
        "fromEmail": "[email protected]",
        "toEmail": "={{$node[\"Switch\"].json[\"email\"]}}",
        "subject": "Send email test true if",
        "text": "Send email True output is ok!",
        "options": {}
      },
      "name": "Send Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 1,
      "position": [
        940,
        520
      ],
      "credentials": {
        "smtp": "SMTP [email protected]"
      }
    },
    {
      "parameters": {
        "fromEmail": "[email protected]",
        "toEmail": "={{$node[\"Switch\"].json[\"email\"]}}",
        "subject": "Send email test false if",
        "text": "Not send false, it only send number false by order, not result!",
        "options": {}
      },
      "name": "Send Email1",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 1,
      "position": [
        820,
        150
      ],
      "credentials": {
        "smtp": "SMTP [email protected]"
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "operation": "append",
        "sheetId": "1FFMzZWLpLUkcSLHENlzZL4i2gCKS9ycVqqqeRwbsbDo",
        "range": "Sheet2!A:C",
        "options": {}
      },
      "name": "Google Sheets1",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        930,
        330
      ],
      "credentials": {
        "googleSheetsOAuth2Api": "Google Sheets OAuth2 API detailhelp"
      }
    },
    {
      "parameters": {
        "dataType": "string",
        "value1": "={{$node[\"Google Sheets\"].json[\"updated\"]}}",
        "rules": {
          "rules": [
            {
              "value2": "1"
            },
            {
              "operation": "notEqual",
              "value2": "1",
              "output": 1
            }
          ]
        }
      },
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 1,
      "position": [
        640,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Send Email1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Google Sheets1",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

From what i’ve noticed, the only way to get a correct reponse from the “False” outputs is to use the merge in a passthrough mode (Or to use another node as passthrough)

I had now a look. The problem is that you use the expression with $node. That one does by default always use the data of the first output (so output with index 0, which is in the case of the IF-Ndoe “true”). If you change your expression to $json it uses the incoming data the node receives and works then as you expect.

So you would have to change the expression from:

{{$node["IF"].json["email"]}}

to:

{{$json["email"]}}

Also realized that our documentation has an error. It says instead of “output” wrongly “item”. We will fix that.

2 Likes

Thanks for detail explain, It’s working like expected now!