setNextRequest() not working as expected, using latest Postman v8.0.6

I am trying to trigger a request run based on the condition in the Test section. Running all these already in collection runner but still, setNextRequest() is not working as expected.
Scenario 1:
If myVar is greater than 0, it should only run the ā€œConfigure Point Pickupā€ API. But currently, itā€™s running ā€œConfigure Point Pickupā€ and ā€œConfigure Roadieā€ API both.

Scenario 2:
If myVar is less than or equal to 0, it should only run the ā€œConfigure Point Pickupā€ and ā€œConfigure GE Self-Deliveryā€. {Used for loop, to trigger scenario 2, not sure if its the correct way but really need to use}
But currently, itā€™s running ā€œConfigure Point Pickupā€ and ā€œConfigure Roadieā€ API both.

Refer attached screenshot for reference.

I believe I follow your scenario. What I see in your last screenshot is if your myVar value is <= 0 youā€™re trying to use postman.setNextRequest multiple times.

That function doesnā€™t work that way. setNextRequest will only trigger the next request. You canā€™t build workflows by calling it a bunch of times in the same request. By the looks of the code, Iā€™d expect the next request to execute in that scenario would be ā€˜Configure Point Pickupā€™

@allenheltondev Yes, even I thought the same that setNextRequest will not trigger multiple times if added under for loop. So what will be the best solution to achieve above scenario 2 as expected?

Also, about scenario 1, If myVar is greater than 0, it should only run the ā€œConfigure Point Pickupā€ API. But currently, itā€™s running ā€œConfigure Point Pickupā€ and ā€œConfigure Roadieā€ API. Is this working as expected?

The workflow is going to continue in the order they are listed in your collection. So if you want to stop execution, youā€™d need to edit the Configure Point Pickup request to do postman.setNextRequest(null) so it will stop running.

For your scenario 2, Iā€™d point it at Configure GE Self-Delivery then update Point Pickup with postman.setNextRequest(null) to stop execution again.