Add the ability to configure workflow level variables and/or global variables

The idea is:

I’d like to be able to set variables that would be available at the workflow level scope - so any node inside a workflow would be able to access the data. The motivation for this is two-fold.

My use case:

  1. make it easier to set values that could be used throughout the workflow. I know you can do this using a code node, or set node, but if you have multiple triggers in one workflow, you’d have to configure multiple versions of the set/code node to configure these values
  2. make it easier to migrate nodes from different environments - for example, dev/test/prod. You could essentially copy a workflow from test to prod and the variables that would change would already be configured in the workflow settings so your workflow would need minimal modifications between environments.

I think it would be beneficial to add this because:

It will help the developer story that works in multiple environments and reduce the amount of work it takes to change things like Base URL values for a workflow that uses lots of HTTP requests.

Any resources to support this?

Not yet

Are you willing to work on this?

I would work on this - I’d need some high level pointers to get started but I could certainly work on it.

Hey @roemhildtg,

This is exactly why we released the variables feature and the upcoming source control feature is the next stage of that so you can do exactly what you are after. These are global variables though rather than workflow level and they can’t be set from a workflow but for setting a URL you can do that with no problem.

2 Likes

Thanks @Jon I was just investigating the new Variables in the 1.x release. Looks like its exactly what, or close enough to what I’m looking for!

1 Like

@Jon hey Jon, I believe there is still merit for workflow level variables, unless I am missing a key feature/functionality.

In my experience (this is a new account but I’ve used N8N since the beginning of the year and have some 15-20 production workflows but absolutely do not claim to be an expert), the flow gets very messy when needing to reference Set nodes in workflows with multiple branches, loops and code nodes executing on all items. I find that the “reference” to previous nodes often gets broken and a combination of merge and set nodes need to be used where a workflow level variable could be used instead. But again, maybe I’m not using N8N properly.

Would absolutely support a $workflow.vars. or similar. Would also appreciate any enlightenment in case I am missing how N8N should be used.

Thanks!

2 Likes

Hey @revhuntr,

Welcome to the community :raised_hands:

You are not wrong, I would also like variables that I can read at a workflow level. For now the only option is to use staticdata which exists at a workflow level or use an external database to store data in and pull it out / set it as needed.

At the moment though our variables are static and can’t be changed but hopefully this will change in the future.

1 Like

Ok, thank you, that confirms it.

Any recommendations for such an external database? I guess I’ll go with spreadsheets for now, or is this known to impact performance a lot? Also, I guess I can use the $exections.id var to create a “scope” for these vars?

No recommendations really it depends on what you are happy with, Redis might work fairly well for it though.

I developed a community node for n8n, named n8n-nodes-globals, which might have what you need. It lets you set up constant values that can be used in all your workflows.

Usage example:

Please test this node and share your experiences or suggestions.

Github repo: GitHub - umanamente/n8n-nodes-globals: N8N community node that allows users to create global constants and use them in all their workflows

1 Like

Thanks, I use cloud so not sure if that applies. I got around it by using google spreadsheets lmao