Execute first request from collection only once

Hello, I created a collection form 5 POST request. The first request is for getting token and I want to execute the request only once on first iteration. After that to start from the second. For example : iteration 1 → Resquest 1,2,3,4,5 and Iteration 2 → Request 2,3,4,5.
That what I did is to create undefind global variable “firstRequestExecuted”

I put below if statments in pre-request with the idea :
iteration 1 → first if set the value of global variable to true.
iteration 2 → second if , check if global variable “firstRequestExecuted” is true proceed with request 2.

if (typeof pm.globals.get (“firstRequestExecuted”) === ‘undefined’) {
pm.globals.set(“firstRequestExecuted”, true);
}

if (typeof pm.globals.get(“firstRequestExecuted”) === true) {
pm.execution.setNextRequest(“SecondRequest”);
}

Please help. What i am doing wrong ?
First request for getting the token is executed every iteration.

That’s not how setNextRequest() works.

setNextRequest() does just that, it sets the next request that will run after the current request and all scripts have run.

The current request will always run.

If you want to skip a request, you can use the skipRequest() feature.

You might also want to consider the iteration counter.

console.log(pm.info.iteration);

You can use this to control whether you skip the request or not.

Great, thank you a lot. It is working now! :partying_face: :partying_face:
Now I am gettomg interation info and if iterations are >=1 I am skipping the request.