Collection variable not updatable by pos-response script

I have created a simple post-response script, the purpose is to request an access token, save that token into a collection variable, which is used as part of the authentication for other requests,

this is the script:


// Stores the Token field in an environment or global variable
console.log( "start post response")
var responseBody = pm.response.json();
var token = responseBody.Token;
console.log( token )
pm.collectionVariables.set("token", token);

console.log(pm.collectionVariables.get("token"))

the script seem to run fine, the logs show the propper values being retrieved from the responseBody then it is successfully retrieved from collectionVariables.get - BUT after the execution, I check the variable inside the collection ant it is empty.

any idea why?

I was able to make it work, I had to include an initial value for the variable, after that the variable worked fine

How are you adding initial value ? you cant do that anymore, there is no initial/currnet anymore ?

image

you are correct, there is only a single value column right now, what I meant to say is that I had never included any value before, I had just included the name of the variable and leave the value column empty.

saving a value for the first time in that interface solved the problem, it seems the variable was not properly initialized before I included a value in that column for the first time.

hope that clarifies