How to Loop Variables from array lists to request body

Hi all, i really need your help guys to figure this out i new to scripting parts

My question:
How to Loop Variables from array lists to request body.

I’ve already tried:

pre-request


var status_list = [""," "," UPCOMING","UPCOMING ", 123456, "123asd", true, "UPCOMING"];

var status;

var count =pm.collectionVariables.get("count");

if(count < status_list.length) {
    status = status_list[count];
    console.log("status",status);
    count++;
}
else if(count >= status_list.length){
     console.log("else")
    count=1;
}
pm.collectionVariables.set("status_list", status_list);
pm.collectionVariables.set("status",status);
console.log("final_status",status);
console.log("count",count);
pm.collectionVariables.set("count", count);


test

const status_list = pm.collectionVariables.get("status_list");
const status = pm.collectionVariables.get("status");
const count = pm.collectionVariables.get("count");

if (status && status_list.length > count && pm.response.code === 400){
    console.log("test_line",)
    pm.test('Check Status Code is 400');
    postman.setNextRequest("Loop Post Parameter");
} else if(status && status_list.length == count) {    
        pm.test('Check status should be UPCOMING', () => {
        if(pm.response.code === 200) {
        var jsonData = pm.response.json().data.items.status;
        pm.expect(jsonData).to.eql("UPCOMING");
        }
     });
}

Hey @prabhu-rr :wave: Welcome to the Postman Community :tada:

If I understand your query correctly, you want to loop over status_list and send request for each element in the array, correct?
If that’s the case, you would need to build a workflow as below:
Get an element from array using pop/shift → Update the array → Send request (Repeat)

sample script

const status_list = pm.collectionVariables.get('count')===0 ? [""," "," UPCOMING","UPCOMING ", 123456, "123asd", true, "UPCOMING"] : pm.collectionVariables.get('status_list')

const status = status_list.shift()
if (status) {
 pm.collectionVariables.set('status',status)
 pm.collectionVariables.set('status_list',status_list)
 postman.setNextRequest('Name of current request')
} else {
 postman.setNextRequest(null)
}

I hope this helps, but please do let me know if this is not exactly what you are trying to achieve :slightly_smiling_face: