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.
- 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.
- 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.
- After the report runs, copy the URL in your browser. If the URL bar is not displayed, click CTRL+N.
- 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.
- 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); } }