web
You’re offline. This is a read only version of the page.
close
Skip to main content
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
I have the same question (0)
  • Verified answer
    RudyZhang Profile Picture
    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Service | Customer Service, Contact Center, Field Service, Guides

#1
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 70

#2
Tom_Gioielli Profile Picture

Tom_Gioielli 25 Super User 2025 Season 2

#3
mk1329 Profile Picture

mk1329 16

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans