基本步骤:

  1. 使用SSRS建立报表,以下的例子是以记录的GUID作为报表的参数
  2. 获取ReportSession 和 ControlId来调用报表
  3. 以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");
}

【原创】Dynamics CRM 2015/2016,以PDF的形式打开SSRS报表。的更多相关文章

  1. Dynamics CRM 2015/2016新特性之三十二:新增乐观并发处理

    关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复215或者20160328可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyong. ...

  2. Dynamics CRM 2015/2016新特性之三十三:有了ExecuteTransactionRequest,再也不用担心部分成功部分失败了

    关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复216或者20160329可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyong. ...

  3. Dynamics CRM 2015/2016 Web API:Unbound Action 和 Bound Action

    上篇文章介绍了Bound/Unbound Function.今天我们来看看Action吧.像我之前说的:Function和Action之前的差别能够简单理解为.Function不改动数据,可是Acti ...

  4. Dynamics CRM 2015/2016 Web API:Unbound Custom Action 和 Bound Custom Action

    今天我们再来看看Bound/Unbound Custom Action吧,什么是Custom Action?不知道的小伙伴们就out了,Dynamics CRM 2013就有了这个功能啦.和WhoAm ...

  5. Dynamics CRM 2015/2016 Web API:Unbound Function 和 Bound Function

    今天我们来看看Dynamics CRM Web API Function 吧, 这是一个新概念,刚接触的时候我也是比較的迷糊.这种命名确实是和之前的那套基于SOAP协议的API全然联系不上.好了,不说 ...

  6. Dynamics CRM 2015/2016新特性之三十四:有了插件日志,调试插件so easy!

    关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复217或者20160330可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyong. ...

  7. Dynamics CRM 2015/2016新特性之七:有了文档模板,打印分析So Easy

    关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复190或者20160216可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! 从CRM 2015 UR1开始, ...

  8. 【原创】CRM 2015/2016,SSRS 生成PDF文件,幷以附件的形式发送邮件

    主要步骤如下: 生成一条邮件记录 生成一条ActivityParty记录 生成PDF文件,并以Base64添加到ActivityMimeAttachment 中去 打开发送邮件窗口,以便编辑及发送邮件 ...

  9. Dynamics CRM 2015/2016 Web API:聚合查询

    各位小伙伴们,今天是博主2016年发的第一篇文章.首先祝大家新年快乐.工资Double,哈哈.今天我们来看一个比較重要的Feature--使用Web API运行FetchXML查询! 对的,各位.你们 ...

随机推荐

  1. weixin设置菜单

    https://jingyan.baidu.com/article/925f8cb8dfcf11c0dce05661.html

  2. [翻译] MMMaterialDesignSpinner

    MMMaterialDesignSpinner Usage To run the example project, clone the repo, and run pod install from t ...

  3. 使用 grep 的 -o 和 -E 选项进行正则的精确匹配

    sed 命令可以很好的进行行匹配,但从某一行中精确匹配某些内容,则使用 grep 命令并辅以 -o 和 -E 选项可达到此目的.其中 -o 表示“only-matching”,即“仅匹配”之意.光用它 ...

  4. Python学习---线程/协程/进程学习 1220【all】

    Python学习---线程基础学习 Python学习---线程锁/信号量/条件变量同步1221 Python学习---同步条件event/队列queue1223 Python学习---进程 1225 ...

  5. 关于动态门户WEB博雅互动的源代码(HTML+CSS+javascript)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. 给腾讯云Linux主机创建Swap文件

    新买的腾讯云主机没有提供Swap分区 理由是由于主机经常因为内存使用率过高,频繁使用Swap,导致磁盘IO过高,服务器整体性能反而下降. 不过用户依然可以使用Swap文件的方式添加Swap. 方法如下 ...

  7. 有用的JS函数

    1. QueryString function queryString(key) { var re = new RegExp("[?&]" + key + "=( ...

  8. Linux中如何配置sudo用户

    Linux中的sudo文件在/etc/sudoers,但不建议直接修改此文件: 可以在/etc/sudoers.d文件夹中新建文件,文件名随意,在文件中添加内容如下: 用户名 ALL=(ALL) AL ...

  9. window下安装好postgreSQL 9.3用cmd命令进入数据库(搞的我这个菜鸟只剩半条命)

    linux下基本没什么问题,但在window操作系统下比较麻烦. 需要添加环境变量path路径:C:\Program Files (x86)\PostgreSQL\9.3\bin 添加postgres ...

  10. 关于javascript的单线程和异步的一些问题

    关于js单线程和异步方面突然就糊涂了,看别人的文章越看越糊涂,感觉这方面是个坑,跳进去就不好跳出来.再去看,看着看着感觉自己明白了一些东西,也不知道对不对,反正是暂时把自己说服了,这样理解能理解的通, ...