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.
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.