# Test with multiple records

**URL:** <https://community.postman.com/t/test-with-multiple-records/38994>\
**Category:** Help Hub\
**Tags:** tests, variables\
**Created:** [September 9, 2022, 3:23pm UTC](https://community.postman.com/t/test-with-multiple-records/38994 "2022-09-09T15:23:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![scottholliday](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@scottholliday](https://community.postman.com/u/scottholliday)\
**Post date:** [September 9, 2022, 3:23pm UTC](https://community.postman.com/t/test-with-multiple-records/38994/1 "2022-09-09T15:23:45Z")

</div>

Hi, I’m trying to post several records with a loop. Below is what I have in the Body, Pre-Request Script, and Tests Sections. I tried to run it just by clicking “Send” and it created the first record but would not repost with record 2 and record 3. This is just a basic test that I want to expand upon if successful. Thank you in advance. I am setting the Authorization Token in the Header as well as the content-type (application/json)

**BODY:**

```
{
"email": "{{email}}",
"first_name": "{{fname}}",
"last_name": "{{lname}}"
}

```

**PRE-REQUEST SCRIPT:**

var emails = pm.environment.get(“emails”);  
var fnames = pm.environment.get(“fnames”);  
var lnames = pm.environment.get(“lnames”);

if (!emails) {  
var email = [“[test1@testco.com](mailto:test1@testco.com)”, “[test2@testco.com](mailto:test2@testco.com)”, “[test3@testco.com](mailto:test3@testco.com)”]  
var fname = [“first1”, “first2”, “first3”]  
var lname = [“last1”, “last2”, “last3”]  
}

var currentEmail = email.shift();  
pm.environment.set(“email”, currentEmail);  
pm.environment.set(“emails”, emails);

var currentFname = fname.shift();  
pm.environment.set(“fname”, currentFname);  
pm.environment.set(“fnames”, fnames);

var currentLname = lname.shift();  
pm.environment.set(“lname”, currentLname);  
pm.environment.set(“lnames”, lnames);

**TESTS:**

var emails = pm.environment.get(“emails”);

if (emails && emails.length \>0) {  
postman.setNextRequest(“createmultipleusers”);  
} else {  
postman.setNextRequest(null);  
}

---

<div class="post-metadata">

**Author:** ![iandouglas736](https://avatars.discourse-cdn.com/v4/letter/i/ea666f/32.png) [@iandouglas736](https://community.postman.com/u/iandouglas736)\
**Post date:** [September 9, 2022, 8:40pm UTC](https://community.postman.com/t/test-with-multiple-records/38994/2 "2022-09-09T20:40:17Z")

</div>

Be sure that when you access the arrays in the environment that you’re using `JSON.stringify()` when you store them, and use `JSON.parse()` when you retrieve them. It might be failing silently on the second run because it’s not getting a structure of data the way you think.
