Extract new data

I’m trying to use this article to extract only new incoming data into the database, the result is ERROR: this.getWorkflowStaticData is not a function [line 4]. What could be the problem?

Creating triggers for n8n workflows using polling ⏲ – n8n Blog

image


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:

Hey @KamaR,

We changed how you reference static data so instead of using this.getWorkflowStaticData you would need to use $getWorkflowStaticData, You can find the documentation on using Static Data here: getWorkflowStaticData | n8n Docs

I will make a note to update that workflow template as well.

1 Like

@Jon it worked for me.
only now I can only get the last added record in the database. But what if there are 2 new entries? I’m trying to increase limit to 2. I’m writing new data to the database. The process worked, he sent these two new records further. After this I create 2 new records again and the process no longer works


Hey @KamaR,

Don’t forget that Static Data can’t be used when running the workflow manually and it will be used when the workflow is running in the background.

The issue will likely be that we limit the query to only return 2 results so it will depend on the data order, You could try adding a sort option and sort by the ID field DESC that should then give you the last 2 records but what would happen if 5 records were added?

As you are using Postgres have you thought about using the Postgres Trigger node which can trigger when an event happens on your table like a record is added, modified or deleted. In theory using this approach you wouldn’t need to use static data as the workflow would only be using the data being sent to it from Postgres.

Another option could be that if you have a created or modified field you could do a select where that field contains a time that happened in the last X minutes.

@Jon postgres trigger node I can’t use. need to do without it

do you mean inside the database?
image

Hey @KamaR,

Those fields look like they would do the job, So you could just do a select based on those fields and if you run your workflow every 5 minutes as an example it would be something like where created_at >= NOW() - INTERVAL '5 minutes' which would give you anything created in the last 5 minutes.

Out of interest why can’t you use the Postgres trigger node? Is it is related to the permissions needed for it?

1 Like

@Jon there is one note, I don’t need all the fields last, but only with a certain type

the database ends up being overloaded and crashes

That sounds like a bug we should look into with the trigger or an issue with the database if it is overloading the server.

With the type you can add that to your query as well.

@Jon I did this - everything works

1 Like

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