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

**URL:** <https://community.postman.com/t/setnextrequest-not-working-as-expected-using-latest-postman-v8-0-6/20778>\
**Category:** Help Hub\
**Tags:** tests, collections, setnextrequest\
**Created:** [February 25, 2021, 7:34am UTC](https://community.postman.com/t/setnextrequest-not-working-as-expected-using-latest-postman-v8-0-6/20778 "2021-02-25T07:34:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kalpeshc09](https://avatars.discourse-cdn.com/v4/letter/k/77aa72/32.png) [@kalpeshc09](https://community.postman.com/u/kalpeshc09)\
**Post date:** [February 25, 2021, 7:34am UTC](https://community.postman.com/t/setnextrequest-not-working-as-expected-using-latest-postman-v8-0-6/20778/1 "2021-02-25T07:34:40Z")

</div>

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.

 ![runner-order](https://us1.discourse-cdn.com/getpostman/original/3X/8/5/85bd022d70e7a32efa9aaba222e2aa0ccd8232b8.png) ![scenario2-runner](https://us1.discourse-cdn.com/getpostman/original/3X/7/7/7744e541575ee820f4c18e99ef40f6c5b66d115d.png) ![scenario2-test](https://us1.discourse-cdn.com/getpostman/original/3X/4/1/41715c1250c8b9a546989273667e533f41813ee3.png)

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [February 25, 2021, 12:32pm UTC](https://community.postman.com/t/setnextrequest-not-working-as-expected-using-latest-postman-v8-0-6/20778/2 "2021-02-25T12:32:46Z")

</div>

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’

---

<div class="post-metadata">

**Author:** ![kalpeshc09](https://avatars.discourse-cdn.com/v4/letter/k/77aa72/32.png) [@kalpeshc09](https://community.postman.com/u/kalpeshc09)\
**Post date:** [February 25, 2021, 1:24pm UTC](https://community.postman.com/t/setnextrequest-not-working-as-expected-using-latest-postman-v8-0-6/20778/3 "2021-02-25T13:24:31Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [February 25, 2021, 1:38pm UTC](https://community.postman.com/t/setnextrequest-not-working-as-expected-using-latest-postman-v8-0-6/20778/4 "2021-02-25T13:38:20Z")

</div>

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.
