# Using postman.setNextRequest() within a pre-request script of a folder dosn't appear to do what I think it should do

**URL:** <https://community.postman.com/t/using-postman-setnextrequest-within-a-pre-request-script-of-a-folder-dosnt-appear-to-do-what-i-think-it-should-do/50497>\
**Category:** Help Hub\
**Tags:** csvdatafile, folders, pre-request-script\
**Created:** [August 11, 2023, 10:54am UTC](https://community.postman.com/t/using-postman-setnextrequest-within-a-pre-request-script-of-a-folder-dosnt-appear-to-do-what-i-think-it-should-do/50497 "2023-08-11T10:54:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![swinster](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@swinster](https://community.postman.com/u/swinster)\
**Post date:** [August 11, 2023, 10:54am UTC](https://community.postman.com/t/using-postman-setnextrequest-within-a-pre-request-script-of-a-folder-dosnt-appear-to-do-what-i-think-it-should-do/50497/1 "2023-08-11T10:54:40Z")

</div>

I have a couple of requests in a folder, and I am using a CSV data file to run the folder multiple times; however, only the second request needs to be run on the 2nd and subsequent iterations (i.e. the first request is only run in the first iteration). To achieve this I tried the following code in a pre-request script of the **folder** , such that:

```auto
iterationCount = pm.info.iteration;
console.log(iterationCount);
if (iterationCount > 0){
    postman.setNextRequest("My_2nd_request");
}

```

I am aware that if the `postman.setNextRequest` function is placed in the pre-request script of a **request** , then this is still called AFTER the current request finishes ([Building request workflows | Postman Learning Center](https://learning.postman.com/docs/collections/running-collections/building-workflows/#setnextrequest-always-executes-last)). I had thought that as this was within the folder, then this will be action before ANY request is made. However, the first request is still called at the beginning of each iteration.

What am I missing?

---

<div class="post-metadata">

**Author:** ![swinster](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@swinster](https://community.postman.com/u/swinster)\
**Post date:** [August 11, 2023, 11:11am UTC](https://community.postman.com/t/using-postman-setnextrequest-within-a-pre-request-script-of-a-folder-dosnt-appear-to-do-what-i-think-it-should-do/50497/2 "2023-08-11T11:11:30Z")

</div>

Ok, I think I get it.

The pre-request script of the _folder_ is simply something that will run before every request in the folder run, and the rules regarding the `postman.setNextRequest` function still apply - i.e. that it will run AFTER the current request finishes. This means that it looks like the first request MUST complete before the `postman.setNextRequest` function takes effect (so you cannot skip the first request at all).

I have just come across [Iterating only a single request inside a collection with test data specified in a csv file - #6 by nishant.shah2](https://community.postman.com/t/iterating-only-a-single-request-inside-a-collection-with-test-data-specified-in-a-csv-file/12772/6), and in this topic, they used a dummy request as the first request. I’m unsure if this is the best option, but it works.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [November 9, 2023, 11:12am UTC](https://community.postman.com/t/using-postman-setnextrequest-within-a-pre-request-script-of-a-folder-dosnt-appear-to-do-what-i-think-it-should-do/50497/3 "2023-11-09T11:12:07Z")

</div>

Closed on November 9, 2023, 11:12am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
