I need assistance converting my rdl report to PDF using Javascript. It would greatly help if I could accomplish this task with just the OpenReport() function to avoid having to convert it into a ppt later on. I am currently working in CRM online.
Below is the code snippet I am using:
function OpenReport() {
debugger;
var formType = Xrm.Page.ui.getFormType();
if(formType != 1){
Xrm.Page.ui.setFormNotification("Please wait while system is generating pdf...", "INFO", "pdfGen");
var rdlName = "KalorikBrandPresentationv4.rdl"; //Replace with your report name
var entityType = "10060"; //Replace
var entityGuid = Xrm.Page.data.entity.getId();
var recordId = entityGuid.replace("{","").replace("}","");
var reportGuid = "ea721b27-44a6-ea11-9688-005056ba540f"; //Replace with your report guid
var url = Xrm.Page.context.getClientUrl() + "/crmreports/viewer/viewer.aspx?action=run&context=records&helpID=" + rdlName + "&id=%7b" + reportGuid + "%7d&records=%7b" + recordId + "%7d&recordstype=" + entityType;
var responseSession = getReportingSession(reportGuid,rdlName,recordId);
convertResponseToPDF(responseSession,rdlName);
}
function convertResponseToPDF(responseSession,reportName) {
debugger;
var pth = encodeURI(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");
var base64PDFString;
var retrieveEntityReq = new XMLHttpRequest();
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]);
}
base64PDFString = btoa(binary);
console.log(base64PDFString);
createNotesAttachment(base64PDFString,reportName);
}
};
retrieveEntityReq.send();
}