Pre-request scripts are not executed

Hello community.

I did a pre-request script that checks the value of an environment variable and increments the value +1 at each iteration and update the value. Everything worked just fine up until some point (after a merge between collections), now it does not check with the environment variables to read the value and does not increment it as well. At every iteration it logs a value smaller than the value that is in the environment variables.

let currentValue = pm.environment.get("env_var");

let incrementedValue = (parseInt(currentValue, 10) + 0).toString().padStart(10, '0');

pm.environment.set("value", incrementedValue);

console.log("value:", incrementedValue);

I did the usual IT guys fixes(quit postman, restart machine, etc), but nothing worked.

Similar scripts are used for other variables, but only this script is not working. Do you have any Ideea why?

Hi @flight-candidate-531. Welcome to the Postman Community :postman_logo:.

Shouldn’t the line parseInt(currentValue, 10) + 0 be parseInt(currentValue, 10) + 1 since you want this to increment the value by 1 on every iteration?

Also, why are you using padStart() here?

Thanks for the help, works fine now after update.
I used padStart strictly for the visibility of the value length and to set an incrementation limit. Output looks like this: 0000012345, 0000012346… and so on.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.