概述
基本步骤:
- 使用SSRS建立报表,以下的例子是以记录的GUID作为报表的参数
- 获取ReportSession 和 ControlId来调用报表
- 以PDF的形式预览报表
一、根据报表的名称获取报表的GUID
//use sdk.soap java script library to fetch record. getReportGuidByName:function(reportName) { var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" + "<entity name='report'>" + "<attribute name='name' />" + "<attribute name='reporttypecode' /> " + "<attribute name='filename' /> " + "<attribute name='reportid' />" + "<filter type='and'>" + "<condition attribute='name' operator='eq' value='" + reportName + "' />" + "</filter>" + "</entity>" + "</fetch>" var fetchQuery = new Sdk.Query.FetchExpression(fetchXml); var results = Sdk.Sync.retrieveMultiple(fetchQuery); return results.view().entities[0].attributes.reportid.fValue; }
二、取得报表的 SessionID 和 ControlID。
//Method to get the SessionID and ControlID for the SSRSReport getReportingSession: function () { var selectedIds = Xrm.Page.data.entity.getId(); var reportName = "<NameofReport.rdl>"; var reportGuid = getReportGuidByName(reportName); //OR 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"); retrieveEntityReq.send("id=%7B" + reportGuid + "%7D&uniquename=" + Xrm.Page.context.getOrgUniqueName() + "&iscustomreport=true&reportnameonsrs=&reportName=" + reportName + "&isScheduledReport=false&p:parameterNamespecified in ssrs report=" + 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; }
三、生成PDF报表并在新的窗口打开
//Method to Download PDF. runReportToPrint: function () { var params = getReportingSession(); 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=public&ContentDisposition=OnlyHtmlInline&Format=PDF"; window.open(newPth, "_self"); }
转载于:https://www.cnblogs.com/bennylam/p/10008430.html
最后
以上就是稳重黑猫为你收集整理的【原创】Dynamics CRM 2015/2016,以PDF的形式打开SSRS报表。的全部内容,希望文章能够帮你解决【原创】Dynamics CRM 2015/2016,以PDF的形式打开SSRS报表。所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复