In the first request, on test I’ll put this code:
let Cities = JSON.parse(responseBody),
CityIds = _.map(body, (city) => city.id);
// Store all the Cities Ids in the environment variable
pm.environment.set('CityIdsList', JSON.stringify(CityIds));
// Store the next index of the array for City ids
pm.environment.set('nextIndex', 0);
// Store the active City ID
pm.environment.set('activeCityId', CityIds[0]);
Then, on the second request I’ll use this one:
let CityIds = JSON.parse(pm.environment.get('CityIdsList')),
nextIndex = parseInt(pm.environment.get('nextIndex')) + 1;
if (CityIds.length === nextIndex) {
pm.environment.set('nextIndex', 0);
pm.environment.set('activeCityId', CityIds[0]);
postman.setNextRequest(null);
} else {
let activeRODID = CityIds[nextIndex];
pm.environment.set('nextIndex', nextIndex);
pm.environment.set('activeCityId', activeCityId);
postman.setNextRequest("Second Request");
}
Perhaps there is a more efficient way to do it, but this will work.