How to setup Splitter and Reference Value directly

Hey! I am trying to acheieve an auto-filter for emails where I can get an output of specific emails details where the subject or body has specific keywords.

Currently I am stuck at a step where I am unable to setup a spliter properly and reference the values directly so I don’t face the challenge that I am only getting values of 1 email in return.

Please share your workflow

n8n version: [email protected]
Database : SQLite (default)
EXECUTIONS_PROCESS setting: Main
Running n8n: via desktop app
Operating system: Windows 10

My expectation would be if there are 200 emails that are scanned in 1 hour, of which 10 have the respective keywords. All those 10 emails subject, body, receiver email, sender email, date and time, and ID details are updated on the google sheet every hour without any manual intervention.

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

That is some very clear explanation that i saw for today…

  1. Add a Split In Batches node after your filter function:
- Set "Batch Size" to 1
  1. In your Google Sheets node, use direct field references:
Subject: {{$json.headers.subject}}
Body: {{$json.textPlain || $json.textHtml}}
Sender: {{$json.headers.from}}
Receiver: {{$json.headers.to}}
Date: {{$json.headers.date}}
ID: {{$json.id}}

This approach processes each matching email as a separate item, allowing all 10 matching emails (out of your 200) to be added to your Google Sheet in a single workflow run.

Make sure your function node that checks for keywords returns the full email object along with your match result.

2 Likes

Hello Prakash, thanks a lot!

I have create this test workflow to check this for 50 emails that were fetched after 4 PM today, before I implement this in my main workflow.

Is the loop over items correct or does it have to go through the complete workflow? I think I am doing something wrong that is resulting in the data to not split correctly

is there a reason why you are checking the matching in a code block,
A better solution would use the n8n nodes to check if they are unique and then use it to check if indiviallity and adding of keyword.

1 Like

Yes, primary reason is I have 74 keywords currently and the list might expand in near future, so I thought this would be most optimized route versus a filter.

Also note I realized in my previous reply I missed to update the function to return email details I require apart from the KeywordFound, that I have updated. Open to suggestion if ther is any better solution to have an ever-expanding list of keywords.

Currently the gsheet tagging is working finally, thanks for the guidance!


Is this what you are expecting

1 Like

Yes, this exactly! And after some tweaking I was able to run the it correctly. You suggestion to return the email data with the function was the key, as I was simple using the function as filter getting the ‘true’ as an answer and then referencing gmail node, instead of getting the data directly passed via the function node to the filter node, and then to the loop.

Grateful for you help again, you were a savior, and I really enjoyed learning something new as a newbie on n8n! Hoping to expand my knowledge further.

1 Like

You words bring happiness to me, If my reply was helpful to you, please consider marking it as the solution and through likes around a bit… HeHeHe

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.