I have this workflow in which I built probably because I simply wanted to explore automation knowing I have no background in programming. This workflow includes Schedule Trigger - Gmail Node - Set Node - Code Node - Sheets Get Rows - IF Node - and Telegram node.
First. Schedule triggers every hour and checks incoming emails from my gmail node. I chose 50 since getting all emails would take a few more minutes. After getting these messages, on Set Node, I put only “FROM” so it could output only the sender emails like “Sender [email protected]”. Afterwards, I am now passing the outputs to the code node in which it will only filter out the raw text excluding the email so this should output “Sender” only. Then, I now put Get Rows from Sheet node and output the current rows in my google sheets. Then, I pass these inputs to the IF node in which I wanted to compare if {{ $(‘Get many messages’).item.json.From }} matches {{ $json[‘SENDER NAME’] }}.
Here’s the problem. It does not output anything on the true node and will only return the false node in which it returns instead the rows from my sheets not any results. I’ve been searching for some solutions and it seems that it’s going nowhere. I need some help on this.
Any help would be appreciated. Thank you.
Describe the problem/error/question
What is the error message (if any)?
Please share your workflow
(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)
Share the output returned by the last node
Information on your n8n setup
- n8n version:
- Database (default: SQLite):
- n8n EXECUTIONS_PROCESS setting (default: own, main):
- Running n8n via (Docker, npm, n8n cloud, desktop app):
- Operating system:
1 Like
Hi @Scrumpey Welcome! Can you please share your workflow with us so that we can look at its configuration and help you resolve this issue & you can share your workflow JSON by CTRL+C in the workspace area and here just select Preformatted Text box and paste it there and also if possible PIN all the nodes so that we can see what kind of data you are dealing with and where exactly it is causing you the error.
I’m not sure how to pin it but you can check the IF node since that is where I got the most problem at on my workflow. Thanks a lot.
@Scrumpey I can look at your workflow but again i cannot suggest you a fix other then random hit and trial advice, if you can please try to run your workflow once and then when it outputs the false branch and stops then select all by CTRL+A and then just press p so that every data in the node would be pinned , and so then copy the workflow and then show us here, as we cannot suggest anything other then random assumptions as everything looks right to us by looking at your workflow setup.
Is this okay? I tried to run and get 10 items instead of 50 for the test run. I did as you requested. Let me know if you need more information for it. Thank you.
The Solution @Scrumpey
You need to restructure your workflow to properly compare the sender names. Here’s the corrected approach:
Better Workflow Structure:
-
Schedule Trigger - Every hour ✓
-
Gmail Node - Get 50 messages ✓
-
Code Node - Extract just the sender name from the “From” field
-
Google Sheets - Get all rows with sender names
-
Code Node - Check if the Gmail sender exists in the Sheets data
-
IF Node - Route based on match/no match
-
Telegram - Send notification
For the comparison Code Node (step 5), use this:
// Get the sender name from Gmail
const senderName = $input.item.json.senderName; // from your first code node
// Get all names from Google Sheets
const sheetNames = $('Google Sheets').all().map(item => item.json['SENDER NAME']);
// Check if sender exists in sheet
const isMatch = sheetNames.includes(senderName);
return {
json: {
senderName: senderName,
isMatch: isMatch,
from: $input.item.json.from
}
};
Then in your IF node:
- Condition:
{{ $json.isMatch }} equals true
Alternative Simpler Approach:
Instead of using an IF node after the code, you could filter directly in the Code node and only output items that match or don’t match.
2 Likes
Thankyou @Scrumpey This helps a lot, the problem here is not in the IF node but in the way you are entering data their , i recommend using the Get Row node before the code node, and the best approach here is to just return a boolean variable like if name matches then true else false, but in case if you are looking for using those names later in the workflow please consider using CodeNode to filter them out and also use Code Node to validate Your Sheet rows as well, this would help to achieve your main goal.