Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to convert SSRS Report to PDF and attach it to a note in V.9

Posted on by 390

Hi All,

The code to generate PDF from SSRS is allover the internet and it seems to work for most, but mine does not seem to work and fails at the method that encodes the output from the reporting sessions parameter this is retrieved. Please look at the below code

function encodePdf(responseSession) {

    //Create request object that will be called to convert the response in PDF base 64 string
    var retrieveEntityReq = new XMLHttpRequest();

     //Create query string that will be passed to Report Server to generate PDF version of report response.
    var pth = Xrm.Page.context.getClientUrl() + "/Reserved.ReportViewerWebControl.axd?ReportSession=" + responseSession[0] + "&Culture=1033&CultureOverrides=True&UICulture=1033&UICultureOverrides=True&ReportStack=1&ControlID=" + responseSession[1] + "&OpType=Export&FileName=Public&ContentDisposition=OnlyHtmlInline&Format=PDF";
    retrieveEntityReq.open("GET", pth, true);
    retrieveEntityReq.setRequestHeader("Accept", "*/*");
    retrieveEntityReq.responseType = "arraybuffer";
    retrieveEntityReq.onreadystatechange = function () {

        if (retrieveEntityReq.readyState == 4 && retrieveEntityReq.status == 200) {
            var binary = "";
            var bytes = new Uint8Array(this.response);

            for (var i = 0; i < bytes.byteLength; i++) {
                binary += String.fromCharCode(bytes[i]);
            }
            var base64PDFString  = btoa(binary);
            createNote(base64PDFString );
        }
    };
    //This statement sends the request for execution asynchronously. Callback function will be called on completion of the request.
    retrieveEntityReq.send();
}


:

And the response from the api call is below:

onabort: null
onerror: null
onload: null
onloadend: null
onloadstart: null
onprogress: null
onreadystatechange: ƒ ()
ontimeout: null
readyState: 1
response: null
responseText: (...)
responseType: "arraybuffer"
responseURL: ""
responseXML: (...)
status: 0
statusText: ""
timeout: 0
upload: XMLHttpRequestUpload {onloadstart: null, onprogress: null, onabort: null, onerror: null, onload: null, …}
withCredentials: false
_async: true
_headers: ["Accept"]
_url: "ephraiminc.crm11.dynamics.com/Reserved.ReportViewerWebControl.axd;
↵
↵
↵<html>
↵<head>
↵&Culture=1033&CultureOverrides=True&UICulture=1033&UICultureOverrides=True&ReportStack=1&ControlID= HTML>
↵
↵
↵<html>
↵<head>
↵<scr&OpType=Export&FileName=Public&ContentDisposition=OnlyHtmlInline&Format=PDF"
__proto__: XMLHttpRequest

even when i copy the url and paste it onthe address Bar, it fails. somewhen with better knowledge please help.

Arun Vinoth I wll appreciate your input.

Cheers 

*This post is locked for comments

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans