Hi All,
I want to auto generate PDF with some fields value and send email that pdf.
Please suggest any good solution.
Thanks!
*This post is locked for comments
Hi Ambar,
please explain little bit about this code.
Please see code below ,implement this
function runReportToPrint(selectedRecords) {
try {
debugger
var selectedid = null;
var reportid = null;
var req = new XMLHttpRequest();
var reportName = "Invoice Report Detail";
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/reports?$select=reportid&$filter=filename eq '" + reportName + ".rdl'", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
debugger;
var results = JSON.parse(this.response);
if (results != null) {
reportid = results.value[0]["reportid"];
//if (selectedRecords != null && selectedRecords.length > 0) {
// for (var i = 0; i < selectedRecords.length; i++) {
// selectedid = selectedRecords[i];
// var params = getReportingSessionhomegrid(reportName, reportid, selectedid);
// var newPth = Xrm.Page.context.getClientUrl() + "/Reserved.ReportViewerWebControl.axd?ReportSession=" + params[0] + "&Culture=1033&CultureOverrides=True&UICulture=1033&UICultureOverrides=True&ReportStack=1&ControlID=" + params[1] + "&OpType=Export&FileName=" + reportName + "&ContentDisposition=OnlyHtmlInline&Format=PDF";
// setTimeout(function () { window.open(newPth, "_self"); }, 1000);
// }
if (selectedRecords != null && selectedRecords.length == 1) {
selectedid = selectedRecords[0];
var params = getReportingSessionhomegrid(reportName, reportid, selectedid);
var newPth = Xrm.Page.context.getClientUrl() + "/Reserved.ReportViewerWebControl.axd?ReportSession=" + params[0] + "&Culture=1033&CultureOverrides=True&UICulture=1033&UICultureOverrides=True&ReportStack=1&ControlID=" + params[1] + "&OpType=Export&FileName=" + reportName + "&ContentDisposition=OnlyHtmlInline&Format=PDF";
setTimeout(function () { window.open(newPth, "_self"); }, 1000);
}
else if (selectedRecords != null && selectedRecords.length == 0) {
alert("Please select a record.");
}
else if (selectedRecords != null && selectedRecords.length > 1) {
alert("Please select only one record .");
}
else {
var params = getReportingSession(reportName, reportid);
var newPth = Xrm.Page.context.getClientUrl() + "/Reserved.ReportViewerWebControl.axd?ReportSession=" + params[0] + "&Culture=1033&CultureOverrides=True&UICulture=1033&UICultureOverrides=True&ReportStack=1&ControlID=" + params[1] + "&OpType=Export&FileName=" + reportName + "&ContentDisposition=OnlyHtmlInline&Format=PDF";
window.open(newPth, "_self");
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
}
};
req.send();
} catch (ex) {
throw ex;
}
}
function getReportingSession(reportName, reportGuid) {
var selectedIds = Xrm.Page.data.entity.getId();
selectedIds = selectedIds.replace('{', '');
selectedIds = selectedIds.replace('}', '');
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");
retrieveEntityReq.send("id=%7B" + reportGuid + "%7D&uniquename=" + Xrm.Page.context.getOrgUniqueName() + "&iscustomreport=true&reportnameonsrs=&reportName=" + reportName + "&isScheduledReport=false&p:invoiceid=" + selectedIds);
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;
}
function getReportingSessionhomegrid(reportName, reportGuid, selectedrecordid) {
// var selectedIds = Xrm.Page.data.entity.getId();
selectedrecordid = selectedrecordid.replace('{', '');
selectedrecordid = selectedrecordid.replace('}', '');
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");
retrieveEntityReq.send("id=%7B" + reportGuid + "%7D&uniquename=" + Xrm.Page.context.getOrgUniqueName() + "&iscustomreport=true&reportnameonsrs=&reportName=" + reportName + "&isScheduledReport=false&p:invoiceid=" + selectedrecordid);
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;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function runReportToPrintReceipt() {
try {
debugger;
var reportName;
var chequeamount = Xrm.Page.getAttribute("cm_chequeamount").getValue();
if (chequeamount != null) {
reportName = "Receipt_Cheque";
}
else {
reportName = "Receipt_Cash";
}
var selectedid = null;
var reportid = null;
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/reports()?$select=reportid&$filter=filename eq '" + reportName + ".rdl'", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
debugger;
var results = JSON.parse(this.response);
if (results != null) {
//reportid = "EEE6E34A-5F1B-E711-8102-5065F38B06F1";
var reportid = results.value[0]["reportid"];
var params = getReportingSessionReceipt(reportName, reportid);
var newPth = Xrm.Page.context.getClientUrl() + "/Reserved.ReportViewerWebControl.axd?ReportSession=" + params[0] + "&Culture=1033&CultureOverrides=True&UICulture=1033&UICultureOverrides=True&ReportStack=1&ControlID=" + params[1] + "&OpType=Export&FileName=" + reportName + "&ContentDisposition=OnlyHtmlInline&Format=PDF";
window.open(newPth, "_self");
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
} catch (ex) {
throw ex;
}
}
function getReportingSessionReceipt(reportName, reportGuid) {
var selectedIds = Xrm.Page.data.entity.getId();
selectedIds = selectedIds.replace('{', '');
selectedIds = selectedIds.replace('}', '');
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");
retrieveEntityReq.send("id=%7B" + reportGuid + "%7D&uniquename=" + Xrm.Page.context.getOrgUniqueName() + "&iscustomreport=true&reportnameonsrs=&reportName=" + reportName + "&isScheduledReport=false&p:ReceiptID=" + selectedIds);
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;
}
Hi,
Did you check these threads, similar type of question is already answered here:
community.dynamics.com/.../151236
community.dynamics.com/.../205829
Hope it will help you.
Thanks
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156