Global variables undefined in pre-request script

Hi.
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.

I have the same problem. Variables with scope “collection variables” or “global” are not saved or updated when changed in Pre-request scripts. Probably a bug :frowning:

Hi Danny! Any updates on this?

If this is for me, as it’s been a while and there are very few examples on the thread of what is going on, it’s going to be difficult to have any input on this topic.

Are you facing a similar problem? Can you provide examples or a short recording of the issue you’re facing in the latest version?

i think i resolved the issue.
from pm.globals.get('apiKeyTest') to pm.environment.get('apiKeyTest')
not sure this is exactly the issue you guys encountered. but i think it is similar from the issue i have encountered.

I believe I found a solution:
steps to use it

  1. go to Global variable, and double click on your variable
  2. Postman will give you an option to make it either global or environmental
  3. select the global option, Postman will cover your variable into {{}} braces, then it can be used as global variable