0

There was an error in evaluating the Pre-request Script: Error: Cannot read property 'name' of undefined

var limit = 50;
pm.sendRequest(getComponentsNewURL, function (err, response) {
   var jsonData = response.json();
   console.log(jsonData.contents[0].name); // able to get name here 
   for (var i = 0; i < limit; i++) {
        if (jsonData.contents[i].name == 'MyHTMLComponentName') { 
            component_id = jsonData.contents[i].id;
            console.log('component_id= ',component_id);
        }
        if(component_id){break};
   }
});
Ranjeet
  • 49
  • 8
  • The size of `contents` array might be smaller than the `limit`. Changing that to `if (jsonData.contents[i] && jsonData.contents[i].name == 'MyHTMLComponentName')` might work. – Vignesh Raja Jun 01 '20 at 05:29
  • @VigneshRaja Thanks for correcting me. It worked :) – Ranjeet Jun 01 '20 at 05:45

0 Answers0