Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Service | Customer Service, Contact Center, Fie...
Answered

cannot download document using ribbon button in Field service mobile app

(0) ShareShare
ReportReport
Posted on by 326
 
HI All,
 
I have added offline button in Field service mobile App Service order entity.
And on click of that button I am trying to download the word file which I have generated using Power automate flow. But it does not download the file, well it works in web field service.
 
Please help me with solution as I am stuck.
 
Our code for reference:
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;        }());
Thanks,
Swetha
  • Verified answer
    RudyZhang Profile Picture
    RudyZhang Microsoft Employee on at
    cannot download document using ribbon button in Field service mobile app
    Hi,
     
     
    Our team analyzed your code and found two errors in it.
     
    First, according to your requirement, you want to download a WORD document, but the content type specified in the code is "application/pdf", which applies to PDF files, not Word files. To download Word files, you should set the correct content type.
     
    Secondly, is the code you shared the complete code? Our team found a syntax error when we tried to analyze your code.

     
    So, we can only try to analyze the download function, the following is the improved code of our team.
    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
        }
    };
    So, would it be convenient for you to provide the complete code, as this will enable our team to pinpoint your problem faster and come up with a solution faster and more efficiently.
     
     
    I hope my answer is helpful to you! If you have any other questions, please feel free to contact me.
     
    Best Regards,
    Rudy Zhang
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,307 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans