locked
How to Save file from CRM Report Server using javascript RRS feed

  • Question

  • Hey,

    I need to download specific report from crm form . so i place a button on ribbon to download the specific report.

    I wrote javascript code get report viewer URl of specific report when i click on that button. It opening report viewer in another window .

    Now i need to download the report as pdf and save it on local folder. in order to do that i need to convert that report to pdf anf make a url with javascript. i needed reportsessionid and control id. to get those id's i have written function but its not giving proper report session id and controtl id. and its giving some some css classes like below.

    https://crm2011.hrc.net/Test/Reserved.ReportViewerWebControl.axd?ReportSession=ad><title>Microsoft CRM Error Report</title><style type="text/css">body{background-color:#EFEFEB;margin: 0px;overflow: auto;}h2{font-size: 16px;color: #aa0000;}td{font-family: Verdana, Arial;font-size: 11px;vertical-align: top;}td.header{border-bottom: solid 1px #999999;color: #004488;font-size: 22px;font-family: Arial Black;}div.err{margin-top: 2px;font-size: 12px;color: #003300;}#leftMenu{background-color: #809D82;border-top: solid 1px #BAD7BC;border-left: solid 1px #BAD7BC;border-right: solid 1px #1F5A1E;border-bottom: solid 1px #1F5A1E;padding-top: 5px;padding-top: 5px;}#spacerBar{border-right: solid 1px #969693;background-color: #C2C2BF;}</style><script language="JavaScript">var _o;function window.onload(){_o = imgGeneral;}function document.ondblclick(){window.open('\x2fHillRomTest\x2f_common\x2ferror\x2fdevError.aspx',"errInfo","width=620,height=420,menubar=1,status=1,resizable=1");}function copyToClipboard(){var debugInfo = document.getElementById("ifrmDebug").contentWindow.document.firstChild.innerText;var generalInfo = document.getElementById("tabGeneral").innerText;var detailInfo = document.getElementById("tabDetails").innerText;var divider = "\r\n\r\n----------------------------------\r\n\r\n";clipboardData.setData("Text", debugInfo + divider + generalInfo + divider + detailInfo);}function glow(bOff){var o = event.srcElement;if (o.src.indexOf("_1") > 0){if (!o.loaded) o.src = o.src.replace(/_1/,"_0");}else{o.src = o.src.replace(/_0/,"_1");}}function load(){var o = event.srcElement;o.loaded = true;_o.loaded = false;_o.src = _o.src.replace(/_1/,"_0");o.src = o.src.replace(/_0/,"_1");document.all(_o.tab).style.display = "none";document.all(o.tab).style.display = "inline";_o = o;}function IsErrorPage(){return true;}</script></head><body title="Double-click to load this page into a new window!"><div style="height:100%; overflow-y:auto;"><table width=100% height=100% style="table-layout:fixed;" cellspacing=0 cellpadding=0 border=0><col width=76><col widt

     I could not figure out where am making mistake..can any one suggest me how to get report session id and control id through javascript..

        var reportName = "Work Order Print 3"; //set this to the report you are trying to download           
        var reportId = "1bfabf87-fcdf-e211-9b2b-000c29bb07f7"; //set this to the guid of the report you are trying to download
        var woid = Xrm.Page.data.entity.getId();
        woid = woid.replace("{", "");
        woid = woid.replace("}", "");
        alert(woid);
        var pth = Xrm.Page.context.getServerUrl() + "/CRMReports/rsviewer/reportviewer.aspx";
        var retrieveEntityReq = new XMLHttpRequest();
        retrieveEntityReq.open("POST", pth, false);
        retrieveEntityReq.setRequestHeader("Accept", "*/*");
        retrieveEntityReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        retr
       // retrieveEntityReq.send("id=%7B" + reportId + "%7D&uniquename=" + Xrm.Page.context.getOrgUniqueName() + "&iscustomreport=true&reportnameonsrs=&reportName=" + reportName + "&isScheduledReport=false");
        retrieveEntityReq.send("id=%7B" + reportId + "%7D&uniquename=" + Xrm.Page.context.getOrgUniqueName() + "&iscustomreport=true&reportnameonsrs=&reportName=" + reportName + "&isScheduledReport=false&p:id=" + woid + "&p:createdon=1/1/9999");
        var x = retrieveEntityReq.responseText.indexOf("ReportSession=");
        var ret = new Array();
        ret[0] = retrieveEntityReq.responseText.substr(x + 14, retrieveEntityReq.responseText.indexOf("&", x) - x - 14);
        //the session id          
        x = retrieveEntityReq.responseText.indexOf("ControlID=");
        ret[1] = retrieveEntityReq.responseText.substr(x + 10, retrieveEntityReq.responseText.indexOf("&", x) - x - 10);
        //the control id        
        return ret;
    }
     var params = getReportingSession();
        var pth = Xrm.Page.context.getServerUrl() + "/Reserved.ReportViewerWebControl.axd?ReportSession=" + params[0] +"&Culture=1033&CultureOverrides=True&UICulture=1033&UICultureOverrides=True&ReportStack=1&ControlID=" + params[1] +"&OpType=Export&FileName=Work+Order+Print+3&ContentDisposition=OnlyHtmlInline&Format=PDF";
        alert(pth);

    After getting Report server url with report session id and control id.. how can i download file from report server url with javascript. ?? please provide me solution..

    Wednesday, July 3, 2013 3:32 PM