In an aura component, I'm passing a list of records of a custom object from the server to a helper function. Now as a JS array of objects, I attempt to add a new property to each object and assign its value depending on whether one field in the original record was populated or another. Whichever was populated will be the new property's value. This is eventually for a datatable column.
The problem is that one of those fields that I check gets considered undefined, even though the field is there and has a value when I log the object. Even stranger:
- When I log the entire object, the field is there with a value.
- When I log the field itself, it's undefined.
- When I loop through the objects keys (all the fields) and log key and value, the field appears and has a value!
Here's the code:
refreshPrereqTable : function(component, event, helper, prereqList) {
prereqList.forEach(prereq => {
console.log('prereq: '+JSON.stringify(prereq));
console.log('prereq.Other_Academic_Institution__c: '+prereq.Other_Academic_Institution__c);
if(prereq.Academic_Institution__c) prereq.AcademicInstitution = prereq.Academic_Institution__r.Name;
//if(prereq.Other_Academic_Institution__c) prereq.AcademicInstitution = prereq.Other_Academic_Institution__c;
Object.keys(prereq).forEach(field => {
console.log(field+': '+prereq[field]);
if(field == 'Other_Academic_Institution__c') prereq.AcademicInstitution = prereq[field];
});
console.log('prereq: '+JSON.stringify(prereq));
});
}
I only attempted to further loop through the fields to see what would result.
Here are the logs:
prereq: {"Other_Academic_institution__c":"Best School","Degree_Level__c":"Professional","Id":"a034P00000YKCebQAH","Name":"0000064","RecordTypeId":"0124P000000bfvpQAA","Application__c":"a004P00000xaBQKQA2"}
prereq.Other_Academic_Institution__c: undefined
Other_Academic_institution__c: Best School
Degree_Level__c: Professional
Id: a034P00000YKCebQAH
Name: 0000064
RecordTypeId: 0124P000000bfvpQAA
Application__c: a004P00000xaBQKQA2
prereq: {"Other_Academic_institution__c":"Best School","Degree_Level__c":"Professional","Id":"a034P00000YKCebQAH","Name":"0000064","RecordTypeId":"0124P000000bfvpQAA","Application__c":"a004P00000xaBQKQA2"}
So the new property (AcademicInstitution) never gets defined and the datatable column I've assigned to it remains blank for the record. Another odd thing is this is a problem in production and not in sandbox.
How is this happening and what is the solution?