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’

@allen.helton 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.