Environment variable is not set properly during Runner

I have a pre-request script that increments an enviroment variable to generate different ids each time a request is generated. Also, I have a runner that calls this request multiple times:

However, I’ve noticed that during the runner the environment variable is not updated, at least in the environment’s tab:

But I monitor the variable in the console log and it is incrementing correctly:

image

My problem is that if I prematurely stop the runner before all the requests end, the environment variable didn’t register all the sets that were executed, and such it keeps the value it had at the beginning of the execution. This may be a known issue or it might just be me using the tools in the wrong way, does anyone have any advice? I can manually set the variable to the value I need after each run but it would be better if the last line of the pre-request script

pm.environment.set(“runnerCounter”, Number(pm.environment.get(“runnerCounter”)) + 1);

always worked by setting the environment variable properly.

Also, I did check the Keep variable values as true, so as to persist any variable changes, even though I’m not sure this is necessary when it comes to environment variables.

i get this problem too…

So, have u resolved it?

Hi @hl32191163

Could you share screenshots of what you have tried?

Thanks a lot. I’ve resolved this by setTimeout() .

i.e.

var json = JSON.parse(pm.request.body.raw);
setTimeout(() => {
    pm.environment.unset("schema_name");
    pm.environment.set("schema_name", json.Name);
    console.log('schema_name was set successfully')
    console.log("schema_name:" + pm.environment.get('schema_name'))
}, 3000)

At this before, i just used environment.set() and tried to get the newer, but the value cannot be updated.