Hello,
I have created a button(Approve) on account entity. If I click on this button it should export data in excel format with field name as column heading. I have written JS code to achieve this requirement.
var accName=Xrm.Page.getAttribute("name").getValue();
var data = [[accName]];
var csvContent = '';
data.forEach(function (infoArray, index) {
dataString = infoArray.join(';');
csvContent += index < data.length ? dataString + '\n' : dataString;
});
var download = function(content, fileName, mimeType) {
var a = document.createElement('a');
mimeType = mimeType || 'application/octet-stream';
if (navigator.msSaveBlob) { // IE10
return navigator.msSaveBlob(new Blob([content], { type: mimeType }), fileName);
} else if ('download' in a) { //html5 A[download]
a.href = 'data:' + mimeType + ',' + encodeURIComponent(content);
a.setAttribute('download', fileName);
document.body.appendChild(a);
setTimeout(function() {
a.click();
document.body.removeChild(a);
}, 66);
return true;
} else { //do iframe dataURL download (old ch+FF):
var f = document.createElement('iframe');
document.body.appendChild(f);
f.src = 'data:' + mimeType + ',' + encodeURIComponent(content);
setTimeout(function() {
document.body.removeChild(f);
}, 333);
return true;
}
}
download(csvContent, 'csv file.csv', 'text/csv');
And the result is:
It is working fine but how to display fields name too..? or Is there any other way to achieve this requirement? like flow or any other?
Thanks in Advance.