Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 46379

Issue in executing SSRS report using JavaScript in CRM Online

$
0
0

Hi All,

I created a SSRS report without any parameter and non-prefiltered report. When I executed this report with below code, it worked perfectly.

Then I made the report prefiltered with parameter name as CRM_QuoteId. I want to know how can I pass the quote id to below code and get the code working?

NOTE: Execution starts from Test method.

var getReportingSession = function () {
    var selectedIds = Xrm.Page.data.entity.getId();
    var reportName = "Quotation.rdl";
    var reportGuid = "53240749-3FC1-E611-80F7-C4346BACDBF8";// Report GUID - Replace with your report GUID

    var pth = Xrm.Page.context.getClientUrl() + "/CRMReports/rsviewer/QuirksReportViewer.aspx";

    var retrieveEntityReq = new XMLHttpRequest();

    retrieveEntityReq.open("POST", pth, false);

    retrieveEntityReq.setRequestHeader("Accept", "*/*");

    retrieveEntityReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    var customReport = "true";
    retrieveEntityReq.send("id=%7B" + reportGuid + "%7D&uniquename=" + Xrm.Page.context.getOrgUniqueName() + "&iscustomreport=" + customReport + "&reportnameonsrs=&reportName=" + reportName + "&isScheduledReport=false&CRM_QuoteId=" + selectedIds.toLowerCase());
    // p:<parameters Name In ssrs> :Is optional when you want to have parameter.
    var x = retrieveEntityReq.responseText.lastIndexOf("ReportSession=");
    var y = retrieveEntityReq.responseText.lastIndexOf("ControlID=");

    var ret = new Array();

    ret[0] = retrieveEntityReq.responseText.substr(x + 14, 24);
    ret[1] = retrieveEntityReq.responseText.substr(x + 10, 32);

    return ret;
};

var encodePDF = function (responseSession) {

    var retrieveEntityReq = new XMLHttpRequest();

    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) {
            debugger;
            var binary = "";
            var bytes = new Uint8Array(this.response);

            for (var i = 0; i < bytes.byteLength; i++) {
                binary += String.fromCharCode(bytes[i]);
            }
            var bdy = btoa(binary);
            Xrm.Page.getAttribute("new_base64").setValue(bdy);
            //CreateEmailAttachment(bdy);
        }
    };
    retrieveEntityReq.send();
};

var test = function () {
    debugger;
    var response = getReportingSession();//getReportingSession();
    var base64String = encodePDF(response);
    //runReportToPrint();
};



Viewing all articles
Browse latest Browse all 46379

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>