TypeError: Cannot read property 'field_547_raw' of undefined

Viewed 15

I am trying to get some code (which was previously working for the last 2 years until a server upgrade) to copy student names from a roster onto a new date using Visual Studios.

Looking in the server logs on AWS, I have a bajillion of:

  • TypeError: Cannot read property 'field_547_raw' of undefined

Does anyone know why this might be? Here is the specific code in question:

//Turn student names into CSV string
let studentNames = _.reduce(inputs.studentDataList, (accumulator, student) => {
  accumulator.push(student.field_548_raw[0].identifier);
  return accumulator;
}, []).join(', ');

//Get the class data and pull out the ID and date
let classResponse = await StudentRosterService.getClassFromStudentRosterRecord(inputs.studentDataList[0].id);

try {
  classResponse = JSON.parse(classResponse);
} catch (exception) {
  return exits.unknownError();
}

let classId = classResponse.records[0].field_547_raw[0].id;
let classDate = classResponse.records[0].field_672;

//Update the student name on class and date on Student Roster records
let promises = [];
promises.push(ClassService.putStudentNamesOnClass(studentNames, classId, inputs.userId));

_.forEach(inputs.studentDataList, (studentData) => {
  promises.push(StudentRosterService.putClassDateOnStudentRosterRecord(classDate, studentData.id, inputs.userId));
});

Any help or insights at all would be greatly appreciated; let me know if there are any further questions that may help clear it up. Thank you for your time.

1 Answers

The error means that the records array at index 0 in classResponse is undefined.

From the code above, I can't tell where the problem is. Try to check the classResponse is correct or not.

Also put let classResponse = await StudentRosterService.getClassFromStudentRosterRecord(inputs.studentDataList[0].id); in the try block in case the promise is rejected.

Related