In the Collection level pre-request script, declare an object without using the var, let or const keywords. The object is then attached to the global sandbox and is available in child context of that collection.
Why it works only for getting variables? When in this same manner I have utils object with a method which changes environmentVariables it doesn’t work. I need to pass explicitly in pre-request script of a request pm to make it work.
As this is an older topic now with a few different solutions suggested, could you share more contextual details about how you have things set up and an example of what’s not working so folks can help you further.