The solution is broken down into 4 steps
- Get the ReportViewer URL and the reportId
- Add an Iframe on an entity form
- Create a JavaScript webresource to set the src(URL) for Iframe.
- 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.
- The report will look like the following screen shot.
- 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
- https://inventive.crm5.dynamics.com/crmreports/viewer/viewer.aspx?action=filter&helpID=Account%20Overview.rdl&id=%7bB13C5C38-BB4B-E111-9453-D8D3855B355E%7d
- 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 below
- 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”.
- 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 (Xrm.Page.data.entity.getId()) var strURL = "/crmreports/viewer/viewer.aspx?action=run&id=%7bB13C5C38-BB4B-E111-9453-D8D3855B355E%7d&records=" + Xrm.Page.data.entity.getId(); //Set iframe URL iframeObject.setSrc(strURL); } }
- 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.