Friday, May 25, 2012

MS CRM 2011: Embed context report to left navigation pane

Idea of this blog post is how to embed report to left navigation pane of Crm editing form. I have found this brilliant post which describes how to embed report into IFrame located on Crm editing form and I took this post as basis for current post.
First step is to create report which will take current record as parameter. Create new report project:

Select Microsoft Dynamics Crm Fetch as a type of data source and input parameters for connection to CRM and click Next:

Input Fetch Xml query for report. Don’t forget to add parameter for filtration by current record:

Define columns that would be displayed at initial layout:

Give your report some name and click Finish:

Initial layout is shown at following screenshot:

I changed report’s layout and after it looked like:

And result of report work:

 Upload report to system and test how it works:
Recheck that parameter is passed from URL to report:
Report’s part is finished. Next part is embedding. Create html webresource which will contain following code (main function of this webresource is to show report inside iframe):
   <script type="text/javascript">
       OnLoad = function () {
           if (window.location.href.indexOf('webresourceeditor') != -1)

           var parentEntity =;
           var reporturl = window.parent.Xrm.Page.context.prependOrgName(
           + parentEntity.getId());
           var reportFrame = document.getElementById("reportContainer");
           reportFrame.src = reporturl;
           reportFrame.onreadystatechange = function () {
               if (reportFrame.readyState != "complete")
               var menubar = reportFrame.contentWindow.document.getElementById('crmMenuBar');
               if (menubar != null) {
          = "none";

               var resultsFrame = reportFrame.contentWindow.document.getElementById('resultFrame');

               var timerId = window.setInterval(function () {
                   var resultsFrame = reportFrame.contentWindow.document.getElementById('resultFrame');
                   if (resultsFrame == null)

                   if (resultsFrame.contentWindow.document.getElementById('ParametersRowreportViewer') == null)

                   resultsFrame.contentWindow.document.getElementById('ParametersRowreportViewer').style.display = "none";
                   resultsFrame.contentWindow.document.getElementById('ParametersRowreportViewer') = "none";
               }, 1000);

       OnResizeComplete = function () {
           var fr = window.document.getElementById('reportContainer');
  = (document.body.offsetWidth - 30) + 'px';
  = (document.body.clientHeight - 30) + 'px';
   <meta charset="utf-8">
<body onresize="OnResizeComplete();" contenteditable="true" onload="OnLoad();">
   <iframe id="reportContainer" src="about:blank"></iframe>

Open account customization form and add new navigation item:

Save and publish form.

No comments:

Post a Comment