I am implemeting an excel import where besides others, a date field is imported to salesforce and inserted as a record. Now I have e.g. an excel sheet where I have a date Format like 01.02.2020 or 02/01/2020 which salesforce won't accept, following the ISO8601 in formattedDateTime. Is there a best practice way to handle such an issue? I saw that there are some possobilities to do so, but I think this doesn't apply to my issue.
I am building up a datatable via the .js-controller
cmp.set('v.customObjectTableColumns', [
{label: 'Name', fieldName: 'Name', type: 'text'},
{label: 'Quantity', fieldName: 'Quantity__c', type: 'number'},
{label: 'Date', fieldName: 'Date__c', type: 'date'}]);
And have the Date__c with type 'date'. The Object type of this custom field is also date. I am reading in the values from the excel sheet here via the .js-helper
fr.onload = $A.getCallback(function() {
let fileContents = fr.result;
let workbook = XLSX.read(fileContents, {
type: 'binary'
});
let rows = XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]]);
let customObjects = [];
for (let i = 0, len = rows.length; i < len; i++) {
for (let j = 1; j <= 5; j++) {
let customObject = {
sobjectType: 'customObject__c',
Name: rows[i]['Name'],
Quantity__c: rows[i]['Quantity']
Date__c: rows[i]['Date']
};
customObjects.push(customObject);
}
}
cmp.set("v.customObjects", customObjects);
});
I think I need to catch the date in the .js-controller or set it even in the view.