基本步骤:

  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. hibernate简单入门教程(一)---------基本配置

    应用级别所以很粗浅 首先介绍一下hibernate框架: 1.优秀的持久化(通俗讲把内存上的短时间运行信息存储在持久化硬盘上)框架. 2.作用于持久层,因为没什么侵入性,所以同样适用于其他层面上的存储 ...

  2. Exchange Server 产品路线图 及 补丁下载

    Exchange Server RU listExchange Server and Update Rollup Build Numbers -TechNet Articles -United Sta ...

  3. contextlib

    contextlib with 语句   上下文 任何对象,只要正确实现了上下文管理,就可以用于with语句. 实现上下文管理是通过__enter__和__exit__这两个方法实现的. 例如,下面的 ...

  4. hmac 算法模块

    Hmac算法:Keyed-Hashing for Message Authentication.它通过一个标准算法,在计算哈希的过程中,把key混入计算过程中 Python自带的hmac模块实现了标准 ...

  5. Asp.Net MVC Identity 2.2.1 使用技巧(二)

    之前我们看到了新生成的项目中跟identity有关的有四个文件,这些文件是基础功能,并未开启identity的全部功能.现在我们先启用角色功能. 1.在App_Start文件夹中的IdentityCo ...

  6. Android 通过触摸动态地在屏幕上画矩形

    需求概述: 在屏幕上用手指画出一个区域,返回所圈的区域坐标. 技术实现: 自定义View,设置画笔及对应参数,在onTouchEvent()回调函数里,对触摸事件进行判断.画出矩形图形. 代码: 自定 ...

  7. December 18th 2016 Week 52nd Sunday

    May your love soar on the wings of a dove in flight. 愿你的爱乘着飞翔中的白鸽,展翅高飞. May my life soar on the wing ...

  8. Iptables教程

    iptables防火墙简介 Iptables也叫netfilter是Linux下自带的一款免费且优秀的基于包过滤的防火墙工具,它的功能十分强大,使用非常灵活,可以对流入.流出.流经服务器的数据包进行精 ...

  9. SOJ 1017 Power of Cryptography 库函数精度

    Background Current work in cryptography involves (among other things) large prime numbers and comput ...

  10. UVa 10288 - Coupons(数学期望 + 递推)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...