Execution order of functions called by pre-request script

This text will be hiddenI have the following pre-request script:

console.log(“Entering test pre-request script - (” + new Date().toISOString() + “)”);

var sleep = eval(pm.globals.get(“sleep”));

// Generate the random vin

getRandomVin = eval(pm.globals.get(“getRandomVin”));


console.log(“Returned from getRandomVin() - (” + new Date().toISOString() + “)”);


console.log(“Sleep completed - (” + new Date().toISOString() + “)”);

var vin = pm.globals.get(“Testvin”);

console.log(“Vin from global was - (” + new Date().toISOString() + "): " + vin);

console.log(“Exiting test pre-request script- (” + new Date().toISOString() + “)”);

The getRandomVinFunction() sends a request to obtain a random automobile vin. The function populates the Testvin global variable with the value. I expected that after calling the function and waiting 5 seconds, that the global variable would be populated by the asynchronous SendRequset code. The log shows that the sendRequest activity occurs after the completion of the pre-request script.

Is there a way to make this behave differently? I don’t think it is unreasonable to want to use the result of a called function later in the same script.

Hey @dmskibba ,

Welcome to the community :wave:

First of all, it may be more useful to open this topic in the help category. I’m sure more help will come from there.

I think that performing this process in the test part, not in the pre-request part, will solve your problem.