Postman body is not getting updated in pre-request script

In Postman pre-request script I am trying to update body with some of my business logic, when I update it and console it, it prints the updated body but do not updates the body while sending request.

In this Screenshot you can see I am creating timestamp and updating it with the help of pm.request.body.update() and also consoling it to see the updated body!

So in console log it is giving updated body with updated timestamp
But when it is actually sending request it is sending the previous timestamp which one I have declared in postman variables

Body I am sending

Please don’t call the variables the same name, as you will have scope issues.

It sounds like you have a collection\environment variable called timestamp (which is what is actually being pulled into the body).

I don’t think the timestamp variable that you are using in the pre-request script will be available outside of that (local) scope. It won’t be available outside of the pre-request script. The body will use the timestamp that is already saved.

What you probably need to do is either update the environment\collection variable that you have already declared or create a new one alongside that to use instead (randomTimeStamp for example). Just after the let timestamp = line.