locked
How to execute Report in Dynamics CRM 2013 to generate PDF in Online mode and offline RRS feed

  • Question

  • Could some one help me out !!! I have got a custom button in the Entity Quote to generate a PDFs file from a report . It work perfectly if the CRM is on-line , but once I switch in to outlook as offline mode it is not working . Because it is not getting a Session id and Control Id

    var pth="";
            if(IsOnline)
            {
            pth= Xrm.Page.context.getServerUrl() + "/CRMReports/rsviewer/reportviewer.aspx";
            }
            else
            {
            pth= " http://localhost:2525/crmreports/viewer/viewer.aspx";
            }
            var retrieveEntityReq = new XMLHttpRequest();
            var Id = Xrm.Page.data.entity.getId();
            var quotationGUID = Id.replace('{', ""); //set this to selected quotation GUID
            quotationGUID = quotationGUID.replace('}', "");
            var reportName = "Quote"; //set this to the report you are trying to download
            var reportID = "6A39D18F-2EC6-E344-8986-F49D6765A723"; //set this to the guid of the report you are trying to download
            var rptPathString = ""; //set this to the CRMF_Filtered parameter
            var strParameterXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'><entity name='quote'><all-attributes /><filter type='and'><condition attribute='quoteid' operator='eq' uitype='quote' value='" + quotationGUID + "' /> </filter></entity></fetch>";
            retrieveEntityReq.open("POST", pth, false);
            retrieveEntityReq.setRequestHeader("Accept", "*/*");
            retrieveEntityReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            rptPathString = "id=%7B" + reportID + "%7D&uniquename=" + Xrm.Page.context.getOrgUniqueName() + "&iscustomreport=true&reportnameonsrs=&reportName=" +
            reportName + "&isScheduledReport=false&p:CRMAF_Filteredquote=" + strParameterXML;
            //remove the part starting from &p:salesorderid if your report has no parameters
            retrieveEntityReq.send(rptPathString);
            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;

    Tuesday, December 16, 2014 6:59 AM