-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
The below error i am getting from salesorce ligthing component and the code is below
({
saveData : function(data, fileName, helper) {
var attachments = data.attachments;
var zip = new JSZip();
var csv = helper.convertArrayOfObjectsToCSV(data.contentDocumentLinks);
alert(data.contentDocumentLinks);
zip.file("Attachments.csv", csv);
var attachmentsFolder = zip.folder("Attachments");
for(var i=0;i<attachments.length;i++){
attachmentsFolder.file(attachments[i].docId + '_' +attachments[i].title + '.' + attachments[i].ext, attachments[i].data, {base64: true});
}
zip.generateAsync({type:"blob"}).then(function(content) {
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
var url = window.URL.createObjectURL(content);
a.href = url;
a.download = fileName;
a.click();
window.URL.revokeObjectURL(url);
$A.get("e.force:closeQuickAction").fire()
});
},
convertArrayOfObjectsToCSV : function(objectRecords){
var csvStringResult, counter, keys, columnDivider, lineDivider;
if (objectRecords == null || !objectRecords.length) {
return null;
}
columnDivider = ',';
lineDivider = '\n';
var keystring = ['RecordId' ,'AttachmentId'];
keys = ['LinkedEntityId' ,'ContentDocumentId'];
csvStringResult = '';
csvStringResult += keystring.join(columnDivider);
csvStringResult += lineDivider;
for(var i=0; i < objectRecords.length; i++){
counter = 0;
for(var sTempkey in keys) {
var skey = keys[sTempkey] ;
// add , [comma] after every String value,. [except first]
if(counter > 0){
csvStringResult += columnDivider;
}
csvStringResult += '"'+ objectRecords[i][skey]+'"';
counter++;
} // inner for loop close
csvStringResult += lineDivider;
}// outer main for loop close
// return the CSV formate String
return csvStringResult;
},
})