How to get current execution ID in the node

I understand that the “Execution ID” of a workflow represents a unique ID for every execution of the workflow. This is needed for a number of reasons like stopping a running execution or saving the execution in the database.

My question is: Is it possible to get the current execution ID from within a node using some metadata method. Something like

this.getWorkflow()
this.getInputData()

?

No that is currently sadly not possible.

What you are describing are actually currently two different IDs.

One is the ID of a currently running execution. Every execution will always get one as it gets used like you already wrote to, for example, stop a running execution. This ID simply resets with each start of the n8n instance and gets incremented by 1 with every execution. This one could theoretically get exposed inside of the workflow.

A totally different ID is the one of the past saved executions. This one is only given to executions that get saved to the database. Depending on the settings that are none, the ones that failed, the ones that did succeed or none. This ID gets incremented by 1 for each saved execution and never resets (unless obviously the database gets deleted).

Thanks for the clarity.

I am trying to get the 2nd one that you mentioned. Assume that the settings are to save the executions are always there, Is there anyway to get it?

No sadly not. The reason is that it does not exist till the workflow finished executing.
Only after it got executed does it check if the workflow should be saved or not (depending on error/success and if it did get started manually). So the ID does simply not exist at that point in time and can so not be returned.

Thank. I have accepted the answer.

1 Like

Just have been made aware of this old topic. It is now possible for a while to get the current execution ID in every expression or Function-Node via: $executionId

11 Likes

Hi. Could you guide me how to write or to use this code? I don’t have knowledge of coding. I am inserting data to mysql, but it requires id. I want to take the id value from execution id.

Hey @CPM,

Would you be able to open a new thread and provide more details on what you are trying to do and what you have so far.

Fyi, the above answer is not up to date anymore. The correct syntax is now $execution.id

1 Like

I have lots of workflow and there is an execution id in the error log file. How can I know which forkflow that this execution id belong