# setNextRequest won't run

**URL:** <https://community.postman.com/t/setnextrequest-wont-run/36111>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [June 10, 2022, 4:17am UTC](https://community.postman.com/t/setnextrequest-wont-run/36111 "2022-06-10T04:17:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hoangdh1012](https://avatars.discourse-cdn.com/v4/letter/h/53a042/32.png) [@hoangdh1012](https://community.postman.com/u/hoangdh1012)\
**Post date:** [June 10, 2022, 4:17am UTC](https://community.postman.com/t/setnextrequest-wont-run/36111/1 "2022-06-10T04:17:55Z")

</div>

I have a request in Postman that will create a User for me. I want to run it automatically for a certain amount of time to save time preparing datas. I try using setNextRequest but it doesn’t work. I have tried to put it in Pre-request Script, Tests tab of the request itself as well as the Collection but it just won’t run. I have certainly sure that all of my item is saved, none of them has orange dots.

```auto
var count = 0;
while(count < 5){
    postman.setNextRequest("CreatePersonWithUser");
    console.log("This is the " + count + " time");
    count++;
}

```

My console log:

```auto
This is the 1 time
 
This is the 2 time
 
This is the 3 time
 
This is the 4 time
 
This is the 5 time
 
POST

```

---

<div class="post-metadata">

**Author:** ![archerZ](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@archerZ](https://community.postman.com/u/archerZ)\
**Post date:** [June 10, 2022, 5:34pm UTC](https://community.postman.com/t/setnextrequest-wont-run/36111/2 "2022-06-10T17:34:18Z")

</div>

Hi @hoangdh1012,

setNextRequest only run within a collection runner. Further more the request you are setting must be in the same collection and sub folder as the request that will execute the set next command. see documentation [Building request workflows | Postman Learning Center](https://learning.postman.com/docs/running-collections/building-workflows/)

---

<div class="post-metadata">

**Author:** ![hoangdh1012](https://avatars.discourse-cdn.com/v4/letter/h/53a042/32.png) [@hoangdh1012](https://community.postman.com/u/hoangdh1012)\
**Post date:** [June 20, 2022, 10:29am UTC](https://community.postman.com/t/setnextrequest-wont-run/36111/3 "2022-06-20T10:29:58Z")

</div>

Thanks. The setNextRequest is working now. But it’s running in an infinite loop instead of following condition of “count”. Could you tell me what’s wrong with it?

---

<div class="post-metadata">

**Author:** ![archerZ](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@archerZ](https://community.postman.com/u/archerZ)\
**Post date:** [June 21, 2022, 1:30pm UTC](https://community.postman.com/t/setnextrequest-wont-run/36111/4 "2022-06-21T13:30:02Z")

</div>

Hi @hoangdh1012,

If you using the same code as above. you need to initialize the count variable elsewhere. The code in the test will be executed every time the request runs and your variable will be initialized at 0 every time causing the loop. You should set that variable up as a collection variable. You can retrieve the collection variables from the test script section using pm.collectionVariables.get().

Check out similar post. [How do I set a Collection variable?](https://community.postman.com/t/how-do-i-set-a-collection-variable/5466)
