Saving Execution Data to Compare in the next Execution

I just migrate from Zapier to n8n, my workflow is like this: fetch some API, compare the id with the id from the last execution. And now I am stuck at how to init the last execution id data and call it in the next execution to compare with the new id from API. Please help!

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:

Welcome to the n8n community! You could try using static workflow data?

Let me make my problem clear, the workflow I want:
fetch API → get id from the last execution → compare and update → some action
and I am stuck at how to init the last execution data to save in, if I put the init in the workflow it will always reset in every execution right? then cannot compare with the last execution to find out if there is a new item from the API call

here is my code testing the getWorkflowStaticData:
const staticData = $getWorkflowStaticData(‘global’);
console.log(staticData)

const newId = $input.all()[0].json.results[0].id;

// Check if the lastId is the same as newId, and stop execution if true
if (staticData.lastIds === newId) {
throw new Error(‘No new item found. Stopping execution.’);
}

// Update the staticData with the newId since it’s different
staticData.lastIds = newId;
console.log(staticData)
const url = $input.all()[0].json.results[0].url
// Return the URL as your result
return [{json: {url: url}}];

when I check the console.log, the first console.log alway return Object {} and the second one is Object {lastIds: }

my workflow is still under testing, does it need to active to store static data?

I active the workflow but it still cannot store the data

Yeah, note that this doesn’t work for manual executions: