Wednesday, February 29, 2012

Step by step tutorial to add a CRM report on an entity form

Today we are going to add a CRM2011 report on an entity form. The report will run on a current record.
The solution is broken down into 4 steps
  1. Get the ReportViewer URL and the reportId
  2. Add an Iframe on an entity form
  3. Create a JavaScript webresource to set the src(URL) for Iframe.
  4. Call the webresource method on form load event.

How to get a ReportViewer URL and reportId

  • To get the reportviewer url and reportId, run the report from Workplace –Reports section as shown in the following screen shot.Report5
  • The report will look like the following screen shot.report1
  • The only thing we need from the above screen shot is URL at the top of the form. If you can’t see the URL press F11. Copy that URL. It will look like following
  • We are going to remove the parts of the URL with yellow background.
  • We don’t need the server and organization path as we will use relative path.
  • We don’t need the helpID parameter as report can run without it.
  • We will change the action = Filter to Run.
  • We will add an another parameter to the URL named “records” to run it on the current record.
  • The modified URL will look like
  • /crmreports/viewer/viewer.aspx?action=run&id=%7bB13C5C38-BB4B-E111-9453-D8D3855B355E%7d&records="

Add an Iframe on an entity form

  • Open the form in the customization mode and add a new tab as shown belowReport2
  • Change the formatting of the section to “One Column” and insert an Iframe. You can set the properties of the Iframe as shown in the following screen shot. Just remember the name of the Iframe is “IFRAME_OverviewReport” not “OverviewReport”.Report3
  • Save the customizations.

Create a JavaScript webresource

  • Create a JavaScript webresource and add the following function to it.
    function showReport() 
        //Get iframe control 
        var iframeObject = Xrm.Page.getControl("IFRAME_OverviewReport");
        if (iframeObject != null)
            //URL we created in first step + id of the current record (
            var strURL = "/crmreports/viewer/viewer.aspx?action=run&id=%7bB13C5C38-BB4B-E111-9453-D8D3855B355E%7d&records=" +;
            //Set iframe URL
  • Check the highlighted line it is the same URL we created earlier in step (How to  a get ReportViewer URL and reportId).
  • Save the changes and publish the webresource.

Call the webresource method on form load event

  • Open the form in the customization mode again and click on form properties.
  • Add the webresource to the form and call the showReport function as shown in the screen shot below.report7
  • Save the form and publish the changes.
  • Test the solution.


  1. >>Just remember to check the “Pass Context” checkbox when adding the function to the form load event

    How do you use it in your code? I don't see any reference to the usage of context.

    1. Hi Andrii

      You are right. I did not need the context. I removed that line.


  2. Hi, is it possible to load Dialog Process into an IFrame control embedded on a custom form with this technique ?

  3. hi , i tried your solution but it asking for credentials when report is loading. we don't want this. can you please help me on this