# Iterating a list of users in postman

**URL:** <https://community.postman.com/t/iterating-a-list-of-users-in-postman/10976>\
**Category:** Help Hub\
**Tags:** variables\
**Created:** [February 24, 2020, 2:48pm UTC](https://community.postman.com/t/iterating-a-list-of-users-in-postman/10976 "2020-02-24T14:48:53Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![j\_who](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/j_who/32/3886_2.png) [@j\_who](https://community.postman.com/u/j_who)\
**Post date:** [March 3, 2020, 4:14pm UTC](https://community.postman.com/t/iterating-a-list-of-users-in-postman/10976/13 "2020-03-03T16:14:25Z")

</div>

**UPDATE**  
@odanylewycz  
I found this article: [How to save a value from response as a environment variable - #5 by aalamakowiecc](https://community.postman.com/t/how-to-save-a-value-from-response-as-a-environment-variable/11000/5)

and using the guidance there - thanks @danny-dainton!  
I changed my test script from this ( **which was not working** :

```
// Test for successful command
pm.test("Status 201, service entry created!", function () { pm.response.to.have.status(201); });

pm.test("Checking for service_entry_id", function () {
    // Parse the response    
    pm.expect(pm.response.json())
        .to.nested.include({
            'args.id': JSON.stringify(pm.iterationData.get('id'))
        });
    console.log("Creating new line item service_task for entry: " + pm.iterationData.get("id"));    
});

postman.setNextRequest("Create Service Line Item");

```

* * *

To this- **which works to set the `{{id}}` variable in my subsequent request for the collection run** 🙂 :

```
// Test for successful command
pm.test("Status 201, service entry created!", function () { pm.response.to.have.status(201); });

// Parse JSON - set environment variable!
var jsonData = JSON.parse(responseBody);
pm.environment.set("id", jsonData["id"]);

postman.setNextRequest("Create Service Line Item");

```

Any tips or ideas on the first question regarding adding a conditional statement or loop to accomodate service entries that have \> 1 `service_task` would be greatly appreciated.  
Thanks!

- J

---

_[View the full topic](https://community.postman.com/t/iterating-a-list-of-users-in-postman/10976)._
