getWorkflowStaticData() generate duplicated data

Hi guys/gals,

The main goal is to have both apps synchronized (Todoist <–> Google Tasks) whenever a task is created, completed,etc. , although for simplicity and since I’m new to n8n nor am I a programmer, I’ve created a workflow that adds a task to Google Tasks whenever a task is created (on a specific project) in Todoist. I’ve followed this article from n8n’s blog about how to use polling, created the Function, but every time the workflow run it adds the new tasks and the older ones and I end up with many duplicated tasks on Google. Any guidance of what am I doing wrong?

const new_items = [];

// Get static data stored with the workflow
const data = this.getWorkflowStaticData(“node”);

data.ids = data.ids || [];

for (let i = items.length - 1; i >= 0; i–) {

// Check if data is already present
if (data.ids.includes(items[i].json.ID)) {
break;
} else {

  // if new data then add it to an array
  new_items.push({
  	json: {
  		id: items[i].json.id,
  		content: items[i].json.content
  	},
  });

}
}

data.ids = items.map((item) => item.json.ID);

// return new items
return new_items;

Hey @nvaz, welcome to the community! It is great to see you here :slight_smile:

Is your workflow activated or are you executing the workflow manually via the Execute Workflow button? From the docs:

It is important to know that the static data can not be read and written when testing via the UI. The data there will always be empty and the changes will not persist. Only when a workflow is active and it gets called by a Trigger or Webhook, the static data will be saved.

Hope that helps! :smiley:

Hi @tanay, thanks for the welcome :smiley:.

The workflow is active and running as scheduled (interval of X minutes)

Thanks

The static data is meant to store minimal information. Depending on the number of tasks, this might get quite big.

This gives access to the static workflow data. It is possible to save data directly with the workflow. This data should, however, be very small.

The only thing you need to store in the static data it’s the last time you pull the tasks. And, you need to use the filter parameters under options. The filters you can use there can be found here.

If I were you, I would go with the webhook API. You do not need to worry whether or not the data has been already processed. Todoist will automatically notify you when a task has a certain state (defined by you, e.x: a task is completed).

Sadly, we do not have a Todoist Trigger node that implements that functionality, but you can always use the Webhook node and achieve the same result.

Thank you very much @RicardoE105, I’ll give it a try.