0
votes

Hi Im Getting Cannot read property 'get' of undefined error while running the Post requisition iterative please help me to resolve this

[
   {
      "first_name": "{{Name}}"
   }
]

Pre-request Script:

var names = JSON.parse(pm.environemnt.get("names"));
if(!names){
names = ["aaa","bbb","ccc,"dddd"];
}
var currentName = names.shift();
pm.environment.set("Name",JSON.stringify(currentName));
pm.environment.set("Names",JSON.stringify(names));

Test Script:

var names = JSON.parse(pm.environemnt.get("names"));
if(names && names.length > 0){
postman.setNextRequest("CollectionReq");
}
else{
postman.setNextRequest(null);
}

Environment: No environment selected

2

2 Answers

0
votes

You have a typo in this statement - JSON.parse(pm.environemnt.get("names")) it should be environment.

This is in the Prerequest and Test scripts.

0
votes

I have modified my test script it worked.

var names = pm.environment.get("names");
if(names && names.length>0) {
  console.log(names);
  console.log(names.length);
console.log(names);
console.log(names.length);
for(var i =0; i< names.length;i++){
postman.setNextRequest("NewPostReq");
}
}
else{
postman.setNextRequest(null);
}