Reference Error is thrown when I try to console log an array object response

Hello Everyone,

I am trying to get the filename from an array response but for some reason I get reference error and I am not able to debug it.

Following is the response from which I am trying to get the filename,

[
  {
    "id": 481,
    "schedulerId": 386,
    "executedDate": "2020-12-18T00:15:09.362797",
    "exportFormatType": 2,
    "fileName": "Schedule Daily_2020-12-18_00-15-07.zip",
    "jobStatus": 1,
    "jobName": "Schedule Daily",
    "jobStatusText": "Completed"
  },
  {
    "id": 480,
    "schedulerId": 469,
    "executedDate": "2020-12-17T17:07:00.815279",
    "exportFormatType": 1,
    "fileName": "test-job failed - json_2020-12-17_17-07-00.zip",
    "jobStatus": 1,
    "jobName": "test-job failed - json",
    "jobStatusText": "Completed"
  }
]

Following is the script which is throwing the error,

tests["Status code is 200"] = (responseCode.code === 200);
if(responseCode.code === 200){
try{
    var jsonData = JSON.parse(responseBody);
    
    console.log(jsonData);
    for(var i=0; i<jsonData.length; i++);
    {
    pm.collectionVariables.set("dwnldFilename"+[i], jsonData.fileName[i]);
    //This should ideally be stored as an array so this array can be used to chain the next request to download.
    }
}

catch(e){
    console.log(e);
  }
}

Following is the error observed in Console,

{type: "Error", name: "ReferenceError", message: "schema is not defined"}
1. type: "Error"
2. name: "ReferenceError"
3. message: "schema is not defined"

I am not sure what I am doing wrong here. Any help will be much appreaciated.

[quote=β€œRajesh_Accion, post:1, topic:18556”]

tests["Status code is 200"] = (responseCode.code === 200);
if(responseCode.code === 200){
try{
    var jsonData = JSON.parse(responseBody);
    
    console.log(jsonData);
    for(var i=0; i<jsonData.length; i++);
    {
    pm.collectionVariables.set("dwnldFilename"+[i], jsonData.fileName[i]);
    //This should ideally be stored as an array so this array can be used to chain the next request to download.
    }
}

catch(e){
    console.log(e);


your code works fine , is there any test that does schema validation ?

I’m not sure where that error is coming from, however, you have an issue with how you are trying to access the filename.

Since your response is an array, you need to use the square brackets before trying to grab the fileName.

pm.collectionVariables.set(`dwnldFileName${i}`, jsonData[i].fileName);