How to get execution ID in the node before finishing the execution

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. I wanted to take this execution ID under the node code that I created during workflow execution to return for users.
IsThere some function that can help me to return the Execution ID?

Hey @Viniciusmq107,

Give this a go: JavaScript Code Snippets | Docs

Edit: that is workflow id not execution so may not be what you are after, could be on the right track though.

Another edit: looking at this it may not be possible: How to get current execution ID in the node - #3 by Talha_Khan

Thanks a lot @jon! The information in the above-linked community post is not up-to-date anymore. The behaviour changed a while ago and now it would theoretically be possible

Welcome to the community @Viniciusmq107!

Can you please clarify. Where do you want to get the execution ID? In the workflow to be used in an expression or in a node you are writing yourself?

Actually just checked. Is already implemented but got never updated in the documentation.

You can access the current execution ID in every expression or Function-Node via $executionId.

1 Like

That is good to know, have you pushed the change to the docs?

No, but created an internal ticket so that @gabriel who is taking great care of our documentation will add it.

1 Like

Updated the Expressions page to add $executionId.

3 Likes

Hey @jan thanks for your answer! I was executing in Function-Node. When I tested $executionId in Function-Node nothing happened, just a error like in this the picture.

Can you show me how can I use this parameter in the code to get the execution ID during execution, because in the Documentation don’t have a example code.

Thanks for your help!

Hey @Viniciusmq107,

Here’s the function that you can use:

const executionId = $executionId;

return [{json:{executionId}}];

Hello @harshil1712 thanks for the help, but look what happened int the execution


the error still persists!

May I know which version of n8n are you using? I ran this on version 0.138.0 and it returns the expected output. If you’re using an older version, can you please update it to the new version?

Let me know if you still face the same issue after updating.

Thanks for the helps! I saw that my version was 0.123.0 now I upgrade the version and fixed the problem
Thanks everybody!

1 Like

Lots of new features / nodes for you to play with then :grinning_face_with_smiling_eyes: