Loop over setNextRequest() function

Hi, I just create one logic. I receive array from API and make a loop to test them. Exactly this kind of loop.
list.map(item => {
if (item.type === 1) {
pm.test(#######, () => {
postman.setNextRequest("#####")
});
} else if (item.type === 2) {
pm.test(###, () => {
postman.setNextRequest("###")
})
} else {
pm.test(######, () => {
postman.setNextRequest(’###’)
})
}
})

I expect it will setNextRequest when postman see this condition. As an example if i have same type 4 out of items it means it should send 4times but actually setNextRequest() didn’t worked.

Do we have such kind of functionality

Setnextrequest doesn’t work as a queued process . It works as the last command wins .

So even if you call setnextrequest 100 times , the setnextrequest will be executed only once that’s for the last one (100th) .

@praveendvd Thanks, i know this rule but want to hear some solution that i can solve the issue

Store the response array to variable

add this to your test script

pm.variables.get("array") ? null : pm.variables.set("array", item)

let counter = pm.variables.get("array")

let type = counter.pop()

switch (type) {

    case 1:

        postman.setNextRequest("1")

        break

    case 2:

        postman.setNextRequest("2")

        break

    case 3:

        postman.setNextRequest("3")

        break

}

pm.variables.get(“array”) ? null : pm.variables.set(“array”, item)

let counter = pm.variables.get(“array”)

let type = counter.pop()

switch (type) {

case 1:

    postman.setNextRequest("1")

    break

case 2:

    postman.setNextRequest("2")

    break

case 3:

    postman.setNextRequest("3")

    break

}

counter.length ? postman.setNextRequest(pm.info.name) : postman.setNextRequest(null)