Global variables undefined in pre-request script

I have a pre-request script that is generating a JWT auth token. Variables are taken from globals variable pool.
When I change workspace very often those variable are unreadable, and therefore undefined.
To solve that I need to edit global envs and just save the changes without any changes.

Postman v8.0.7 Working on Ubuntu

Hey @m.hernik :wave:

The Global scope is for each workspace so if you have Variable A in Workspace 1 you wouldn’t see that Variable when switching Workspaces.

Have you tried moving the scope of that Variable down to the Environment level, that way it would be part of Prod?

Hi Danny.
I’m not sure I follow.
So I have Variable A in workspace 1, but when I switch to workspace 2 and back to 1 I won’t be able to access that anymore?
I don’t have problem with variable per environment so I’m sure that when I move this will variable down this will work, but then the point of having this var globally for all envs is gone, right?

Forgive the Workspaces in the images, just using this as a demo. :grinning_face_with_smiling_eyes:

All the Global variables for a Workspace, are only available within that Workspace.

Those variables are not globally accessible across all workspaces.

If the Global variable is available in the workspace where you’re accessing it using pm.globals.get('var_name') then it should be resolved correctly but if it’s not part of that Workspace, it would be undefined.

All the Global variables for a Workspace, are only available within that Workspace.

That’s clear. But I am in the workspace in which I have environments dev/stage/prod and all those are sharing the same global variable: serviceAuthBaseUrl.

The problem is, that very often when I switch between workspaces this variable is undefined. I have to enter the edition screen and overwrite the value for it to be seen by pre-request script.

If it’s in the initial value and saved - It shouldn’t just unset itself, unless there is something in your Collection doing that.

It’s going to be difficult to suggest anything here because I can’t see what you’re doing or know what’s part of the Collection/Workspace. :grinning_face_with_smiling_eyes:

Seems like it stopped working for me as well.
Even more it stopped overriding global variables with environment ones.

I have pre request script with pm.globals.get(“url”).
I logged url in that script and was undefined.
Then I changed environment (diferent url) and it logged GLOBAL value.
So it is related to what thread owner said.

The workspace is about half a year old so it worked before.