# Looping Same request for multiple time for uploading file doesn't work on newman and testrunner with .setnextrequest

**URL:** <https://community.postman.com/t/looping-same-request-for-multiple-time-for-uploading-file-doesnt-work-on-newman-and-testrunner-with-setnextrequest/15208>\
**Category:** Help Hub\
**Tags:** loop, variables, tests, collections, request\
**Created:** [August 20, 2020, 7:51pm UTC](https://community.postman.com/t/looping-same-request-for-multiple-time-for-uploading-file-doesnt-work-on-newman-and-testrunner-with-setnextrequest/15208 "2020-08-20T19:51:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gpub1](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gpub1](https://community.postman.com/u/gpub1)\
**Post date:** [August 20, 2020, 7:51pm UTC](https://community.postman.com/t/looping-same-request-for-multiple-time-for-uploading-file-doesnt-work-on-newman-and-testrunner-with-setnextrequest/15208/1 "2020-08-20T19:51:56Z")

</div>

Have simple request POST, how to upload file for different files  
TC 1- \> Upload with .text file  
TC 2-\> Upload with .doc file  
TC 3-\> upload with .docx file  
TC 4 - \> Upload file with .jpg file  
TC 5 → Upload file with .pdf file

![image](https://us1.discourse-cdn.com/getpostman/original/3X/a/0/a0a73a7fb38ccf3c0e8d2b3cbd6926b91c226363.png)

@singhsivcan any leads

---

<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:** [August 25, 2020, 11:33am UTC](https://community.postman.com/t/looping-same-request-for-multiple-time-for-uploading-file-doesnt-work-on-newman-and-testrunner-with-setnextrequest/15208/2 "2020-08-25T11:33:07Z")

</div>

Why does it need to be the same request in a loop?

Can you not just make these all separate requests?

---

<div class="post-metadata">

**Author:** ![gpub1](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gpub1](https://community.postman.com/u/gpub1)\
**Post date:** [August 25, 2020, 2:19pm UTC](https://community.postman.com/t/looping-same-request-for-multiple-time-for-uploading-file-doesnt-work-on-newman-and-testrunner-with-setnextrequest/15208/3 "2020-08-25T14:19:29Z")

</div>

lol that’s the easy …did the same it increased my collection numbers though(which i didn’t wanted initially, but that solves the purporse though) 😉 and btw any idea why i get the this error `"status": "JSONArray[0] not found ` works well in another environment, but when i change the env got this error.

---

<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:** [August 26, 2020, 11:34am UTC](https://community.postman.com/t/looping-same-request-for-multiple-time-for-uploading-file-doesnt-work-on-newman-and-testrunner-with-setnextrequest/15208/4 "2020-08-26T11:34:42Z")

</div>

Where are you using JSONArray? I assume that’s a variable you have somewhere?

Maybe it doesn’t exist in your new environment

---

<div class="post-metadata">

**Author:** ![gpub1](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gpub1](https://community.postman.com/u/gpub1)\
**Post date:** [August 26, 2020, 1:36pm UTC](https://community.postman.com/t/looping-same-request-for-multiple-time-for-uploading-file-doesnt-work-on-newman-and-testrunner-with-setnextrequest/15208/5 "2020-08-26T13:36:24Z")

</div>

Figured it out… its was not the variable though but Json body was corrupted with one line part 🙂 thanks for your inputs.

---

<div class="post-metadata">

**Author:** ![gpub1](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gpub1](https://community.postman.com/u/gpub1)\
**Post date:** [February 22, 2021, 8:50pm UTC](https://community.postman.com/t/looping-same-request-for-multiple-time-for-uploading-file-doesnt-work-on-newman-and-testrunner-with-setnextrequest/15208/6 "2021-02-22T20:50:22Z")

</div>

@singhsivcan @danny-dainton request does executed 3 times in runners any help?

pre-request  
`pm.environment.set("counter", 3);`

```auto
var currentCount = pm.environment.get("counter"); 
if (currentCount > 0)
{ 
currentCount = currentCount -1; 
pm.environment.set("counter", currentCount); 
postman.setNextRequest("NextRequestName"); 
console.log("Documents left: "); 
console.log(pm.environment.get("counter")); }

```
