Hi, I would like to use n8n to trigger a sequence whenever something occurs in my app / database.
For example, the most basic scenario is when a new users signs up for an account - this results in a new row inside the Users table.
What is the recommended way to store a variable, such as user ID somewhere in n8n?
I’m thinking this way I could:
- Get data from Mysql every X amount of time (trigger: interval + node: mysql)
- Then check which IDs are bigger than the one I have stored
- Do something with those IDs (let’s say send them an email)
- Update the state in the variable to remember for the next run, which IDs were processed.
The workflow would probably look something like the screenshot below, but I’m missing the piece that would allow me to know what IDs were processed already.
Thanks for any tips on the matter!
n8n version 0.188.0
running on Docker
Hi @Matija_Kovac, you could consider using n8n’s static workflow data to store which row you have last processed. This would require a bit of code though (check out the docs for details) and most importantly does not work when manually running/testing your workflow.
So perhaps you might want to consider adding an additional column (something such as processed_by_n8n) instead and simply update it whenever you’re processed an item (and then use it in your query, of course)?
Hi Tom,
thanks for getting back to me, both options look interesting - I’ll look into this and see what works best for my use case.
Replying to all those that stumble upon.
I switched from zapier this was a heavily used trigger I used for my Application. In order to make a zapier style polling. I created a 1 row table in n8n. Every 2min do a poll bring in the table which has the SQL Table Row ID of the last ran row. After brining in my table the SQL quary included the last transaction Row ID. This is especially handy if the SQL you are working with is not part of application you own so modifying SQL is frowned upon by the application vendor. you areThen at the very end of the task I updated the n8n tables row to the newly ran Transaction row ID. Only problem which I hope n8n comes with built in solution is that it shows that task executed every 2 mins which makes searching for runs difficult.