Iterating a list of users in postman

UPDATE
@odanylewycz
I found this article: How to save a value from response as a environment variable - #5 by aalamakowiecc

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 :slight_smile: :

// 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