Serviceorder.prototype.downloadWordFile = function (fileBody, fileName) { var byteCharacters = atob(fileBody); //@ts-ignore Xrm.Utility.closeProgressIndicator(); var byteNumbers = new Array(byteCharacters.length); for (var i = 0; i < byteCharacters.length; i++) { byteNumbers[i] = byteCharacters.charCodeAt(i); } var byteArray = new Uint8Array(byteNumbers); var blob = new Blob([byteArray], { type: 'application/pdf' }); var link = document.createElement('a'); link.href = URL.createObjectURL(blob); link.download = fileName; link.click(); }; return Serviceorder; }());
Serviceorder.prototype.downloadWordFile = function(fileBody, fileName) {
// Decode the Base64-encoded file content into binary data
var byteCharacters = atob(fileBody);
// Create a Uint8Array array to store the file content
var byteArray = new Uint8Array(byteCharacters.length);
for (var i = 0; i < byteCharacters.length; i++) {
byteArray[i] = byteCharacters.charCodeAt(i);
}
// Create a Blob object with the correct content type
var blob = new Blob([byteArray], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' });
// Create a link element
var link = document.createElement('a');
link.href = URL.createObjectURL(blob);
// Set the file name for the download
link.download = fileName;
// Add error handling
var errorHandler = function() {
console.error('Unable to download the file.');
};
// Asynchronously trigger the file download
if (navigator.msSaveBlob) { // For IE11 and Edge browsers
navigator.msSaveBlob(blob, fileName);
} else {
link.style.display = 'none'; // Hide the link element
document.body.appendChild(link); // Add the link element to the page
link.click(); // Trigger the click event to start the file download
document.body.removeChild(link); // Remove the link element after the download is complete
}
};