Collection variable doesn't update in Postman


I’ve got pre-requests with 2 pm.sendRequest. One of them depends on variable from first response.
They work with setTimeout.

//I set Timeout because updateInfoRequest needs to wait and get it from h2hRequest response
setTimeout("updateInfo", 3000)

updateInfoBody = {"orderId":pm.collectionvariables.get("orderId")}

updateInfoRequest = {
there is connection info

pm.sendRequest(h2hRequest, function(error, h2hResponse){

function updateInfo(){
pm.sendRequest(updateInfoRequest, function(error, updateInfoResponse){

h2hRequest works. It takes orderId.
It doesn’t put in orderId variable after the first call. But I see the value in collection variables.
If run it again - orderId is in variable. But it is the last orderId not new.

I use only Request Tab, not flow or anything else.

How to make pre-request get new orderId every time?

clear or unset commands doesn’t help.

Local pre-request variable answers ReferenceError.

Postman for Windows version 10.10.9. Works without internet connection. I can’t update version following company policy

1 Like

The sendRequest() function is asynchronous in nature, which means the functions don’t wait for the response before continuing to execute the rest of your code. Which also means you cannot guarantee the order that the two sendRequest() will execute or that request A) has completed before you run request B).

Look up asynchronous requests in the forum.

You should see several topics and examples on how to ensure that the requests run in the correct order.

Thank you, I will look up.

But following setTimeout (10000ms) and logs I see that request A always gets the response before running request B.

And it works for 4 another requests with such constructions.

Do you know any cases how to do that?

Executing sync requests programmatically from a pre-request or test scripts - :person_raising_hand: Help - Postman Community

1 Like

For Postman 10.10.9 I found the solution.
setTimeout for updateInfo
function updateInfo(){
pm.sendRequest({Put all request info in here}, function(error, updateInfoResponse){ })}

The orderId isn’t updated if I declare updateInfoRequest not in timeout sendRequest.
setNextRequest doesn’t work in my old Postman.

1 Like

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