Need to give explicit wait between two pm.sendrequest() to make executable sequential

Hi
I am using pm. sendRequest() inside two test functions.

Working Snippet

transferinsufficientbalance()
function transferinsufficientbalance() {
const expression =
pm.globals.get(“idempotent”);
eval(expression);
const req = {
url: pm.environment.get(“url”) + '//v1/’,
method: ‘POST’,
header: {‘psmUserID’:'
’
},
body: {
mode: ‘raw’,
raw: JSON.stringify({ “from”:{“psmUserID”: "", “useDefault”:true ,“network”:“stellar”},“to”:{“psmUserID”:"
",“useDefault”:true,“network”:“stellar”},“size”:“100000”,“assetID”:"*****",“idempotentID”:pm.globals.get(“idempotentID”)})
}
};
pm.sendRequest(req, function (err, res) {
console.log(err ? err : res.json());
pm.test(“Validate whether sender doesnt have enough balance”, function () {

    if (res.code == 200) {

      pm.expect(res.json().status.type).to.eql("failed");
        pm.expect(res.json().status.errorCode).to.eql(1007);
        pm.expect(res.json().status.errorMessage).to.eql("The sender doesn't have enough balance");
             }
    else {
        pm.expect(res).to.have.property('code', 200);
         }
    
    });
});

}
// 3.To Validate whether account is present for the given psmUserID
accountpresentinuserid()
function accountpresentinuserid() {
const expression =
pm.globals.get(“idempotent”);
eval(expression);
const req = {
url: pm.environment.get(“url”) + '//v1/’,
method: ‘POST’,
header: {‘psmUserID’:'
’
},
body: {
mode: ‘raw’,
raw: JSON.stringify({ “from”:{“psmUserID”: "", “useDefault”:false,“accountID”:“123” ,“network”:“stellar”},“to”:{“psmUserID”:"
",“useDefault”:false,“accountID”:“000”,“network”:“stellar”},“size”:“1”,“assetID”:"
**",“idempotentID”:pm.globals.get(“idempotentID”)})

    }
};
pm.sendRequest(req, function (err, res) {
    console.log(err ? err : res.json()); 
 pm.test("Validate whether account is present for the given psmUserID", function () {
    if (res.code == 422) {
     console.log(res.json());
      pm.expect(res.json().errorCode).to.eql(1010);
        pm.expect(res.json().errorMessage).to.eql("Sender's blockchain account not found");
             }
    else {
        pm.expect(res).to.have.property('code', 422);
         }
    
    }
});

}

Now i am facing the issue of pm.sendRequest() not running in one after other.
Can i know how to give explicit wait time inbetween the request

HI @Lalith_Vignesh,
Not really clear what you’re trying to do there, the formatting looks a bit odd.
But in any case, the pm.sendRequest() method is asynchronous, so if you need the requests to be called one after the other (ie. synchronously), you can either set them up as proper requests in your collection, or you if you really want to use pm.sendRequest() you need to perform the second one inside the callback function of the first one.
eg.

let req1 = {...};
let req2 = {...}; // optionally define req2 before calling req1
pm.sendRequest(req1, function (err1, res1) {
   .... 
   let req2 = {...}; // or // optionally define req2 after receiving response to req1
   pm.sendRequest(req2, function (err2, res2) {
      .... 
   });
   .... 
});

Thanks for the update.But need to know how do we perform same request with different test data if we call the function inside the function.
Ex
Three sets of test data for the same post request.if i use three sendrequest inside a single function as per your suggestion.Please let me know how and which testdata will be accessed.

no worries, the two requests share the same variable scope, so you can define req1 and req2 at any place in the code before they are used. I have added it to the example code. Just try it out and see how you go with it.