How to update a request object saved using pm.enviroment.set("req", pm.request)

I have saved my request as object by doing:
pm.environment.set(“Create Draft”, pm.request)

now I have to reuse it in a pre request script :
pm.sendRequest(pm.environment.get(“Create Draft”)
But first I need to update variable in body of this request which is a global variable and already updated by earlier request this is still using old value when this request was saved.

Hi @Ejaz_Mobashir
Welcome to the community

Trying to get better clarification on what you’re facing.

One thing to keep in mind, if you are planning to save an entire request you may need to stringify it first before you put it into an environment variable.

Check out this blog to learn more : When and How to Use JSON Serialization in Postman | Postman Blog

Ideally you will want to use stringify to set your env variable :
pm.environment.set("var-CreateDraft", JSON.stringify(var));

Now in the pre-request script you will have to parse that json to get the env variable to send :

var Obj = JSON.parse(pm.environment.get("var-CreateDraft"));

The pm.sendRequest method sends an API call within test. So you may need to include URL details here : Postman JavaScript reference | Postman Learning Center

you can take a look at how some of these requests are used in this example collection :
https://www.postman.com/postman/workspace/published-postman-templates/collection/20021534-65df9ce8-b487-4618-8784-3caaf64e10c1?ctx=documentation

^ Take a look at folder Using pm.sendRequest to learn more

Hi @pooja-mistry thanks for reply.
In one of my request test I am using this “pm.environment.set(“Create Draft”, pm.request)” to save the request, and its saving in my enviroment variable as “[object Object]”

In another request pre request script I am using a same type of saved request and updating a variable, but this updated value of variable is not being used by above request when I am using that request in pre request script. Its using the value when that request is saved.
Screenshot 2022-05-20 172900


All the request are going in correct order but as I mentioned its not taking updated variable value. I am not sure what I want to do is correct?
I can directly create new request instead of using pre-request script, that will work easily.