How to read workflow name/id inside nodes?

In am interested in reading the Name and ID of a saved workflow inside nodes.

I can see that the node execution functions are defined by the interface IExecuteFunctions and the following is already available inside nodes

Input data using getInputData
Node params using getNodeParameter and
Mode using getMode.

But there is no function to get the name/ID of a workflow. How can that be done? Any help would be appreciated.

Thanks

There is the getWorkflow() method. It returns an object with the basic workflow metadata:

  • id
  • name
  • active

So I had a previous version (0.48) and this method did not exist back then. Moving on, I took the latest code and tried to use it inside the mongodb node

const meta = this.getWorkflow();

This results in a build error of the form

nodes/MongoDb/MongoDb.node.ts:176:21 - error TS2554: Expected 1 arguments, but got 0.
176  	const meta = this.getWorkflow();
 	                  ~~~~~~~~~~~~~

../workflow/dist/src/Interfaces.d.ts:118:17
118     getWorkflow(workflow: Workflow): IWorkflowMetadata;
                    ~~~~~~~~~~~~~~~~~~
An argument for 'workflow' was not provided.
Found 1 error.

It appears that the signature of the method is not correct. Its expecting a Workflow object to be passed which is not available in nodes.

I think I have a simple fix for this this that just changes the signature of this method from

getWorkflow(workflow: Workflow): IWorkflowMetadata;

to

getWorkflow(): IWorkflowMetadata;

I can raise a PR if you add my user to be able to contribute to n8n.

Yes your are right the interfaces were defined wrong. Still wonder why TypeScript did not error as the implementation was done without the “workflow” parameter.

About PR. There is nothing to add you too. Every Github user can create a PR.