Tip #43: Embed a pre-filtered report in an iFrame

One of the benefits of the Microsoft Dynamics CRM SSRS pre-filtering capabilities is that you can run a report in context of a record, such as an account, so when you run the report, it just shows data related to that record. Reports can also be embedded in forms with iFrames, and prefiltering is very handy to make the embedded report reflect just the record you are viewing on the form.

    1. Add an iframe to your form in which to display the report. In this example I called it “IFRAME_Report.” Set the URL for the iFrame to about:blank and uncheck the “Restrict cross frame script” checkbox.
    2. Run the prefiltered report from the report menu or the form “run report” button. If you see the filter screen, filter the report to the desired record.
    3. After the report runs, copy the URL in your browser. If the URL bar is not displayed, click CTRL+N.
    4. Replace the highlighted lines in the following function to match your report URL. Note–you don’t want the website domain part of the URL–the /crmreports/viewer… URL makes it dynamic, so the report should work in any environment, as well as offline.
    5. Call the showReport function in the OnLoad event.
function showReport()
{
   //Get iframe
   var iframeObject = Xrm.Page.getControl("IFRAME_Report");

   if (iframeObject != null) {
      var strURL = "/crmreports/viewer/viewer.aspx"
         + "?action=run&context=records&helpID="
         + "Name%20of%20Report"
         + ".rdl&id=%7b"
         + "33db4d7f-446e-e311-940f-005056ab530d"
         + "%7d&records="
         + Xrm.Page.data.entity.getId()
         + "&recordstype=1";

      //Set URL of iframe
      iframeObject.setSrc(strURL);
   }
}

10 thoughts on “Tip #43: Embed a pre-filtered report in an iFrame

  1. Jon says:

    Thank you for this post. I’m wondering if this has been used in IE 10 and beyond while using CRM Online. When using IE 8 or Google Chrome, the code above works great. On a different machine running IE 10, the report is displayed a bit strange. It is centered vertically in the iFrame so that there is white space above and below the report. Due to this, only the first record in the report is displayed, and when you use the report navigation to move to the next page, it shows the first record of the second page while leaving out all other records. Has anyone else experienced this? Is there a trick to getting the report to display properly?

    • Joel Lindstrom says:

      Jon,
      What you describe is a bug introduced in UR 2 for 2013 and UR 16 for CRM 2013. This broke the report viewer when embedded in the iframe. Fortunately this is confirmed as fixed in UR 17 for 2011 and SP1/Leo which is the end of May.

      As you mention, it affects IE 9-11 (not IE8, chrome, firefox, safari).

  2. […] you have tried Tip # 43: Embed a pre-filtered report in an iframe lately, you may have found the results were not quite as advertised, at least in Internet […]

  3. […] you have tried Tip # 43: Embed a pre-filtered report in an iframe lately, you may have found the results were not quite as advertised, at least in Internet […]

  4. Julie O'Kane-Gill says:

    I have a BIDS report running in a Iframe using the filtered views. I keep getting asked to enter user name and password. I believe this can be overcome using the report controls in the datasource section. Do I use a custom data source or an shared one one? Also what credentials should I use to connect with? Any help will be appreciated.
    Many thanks
    Julie

  5. Jarrod says:

    Thanks for a great article. I was able to get my report embedded and looking great. Then one of my users reported that they were getting a 404 for the fram when viewing via 2013 Outlook. I have the URI listed below for how it shows up in IE and then in Outlook. I haven’t ever seen anything like this.

    In IE:
    /org/_forms/read/crmreports/viewer/viewer.aspx?action=run&context=records&helpID=MO%20Overall%20Gauge.rdl&id=%7b66ec345a-ea39-e511-9444-000c29404569%7d&records={FAE5D8D3-0A0A-E511-943E-000C29404569}&recordstype=10002 HTTP/1.1

    Outlook:
    /org/crmreports/viewer/viewer.aspx?action=run&context=records&helpID=MO%20Overall%20Gauge.rdl&id=%7b66ec345a-ea39-e511-9444-000c29404569%7d&records={FAE5D8D3-0A0A-E511-943E-000C29404569}&recordstype=10002 HTTP/1.1

    Any ideas why it would format this way?
    Thanks!

  6. Charlotte says:

    Have tried the above but getting “Reporting Error – The expected parameter has not been supplied for the report” – Any help?

Leave a Reply

Your email address will not be published. Required fields are marked *