Embedding CRM reports in IFrames using the CRM2011 Report Viewer

It is quite common for users to request that reports be included in Iframes on forms, or in Dashboards. Although this can be done by pointing the Iframe directly at SQL Reporting services, this essentially bypasses the CRM Report connector and relies on the user authenticating directly with SQL Reporting Services and SQL Server. If you have SQL Server and Reporting Services on the same server or Kerberos is set up correctly, this isn't a problem. If however your users can only access the report through the CRM Front end, then you need to use the CRM Report review rather than the Reporting Services native one.

1) Create a html web resource named 'ReportViewer' or similar

<script src="ClientGlobalContext.js.aspx" ></script>
<script type="text/javascript">
    function submitForm() {
        var form = document.forms[0];
        var context = GetGlobalContext();
        form.action = context.getServerUrl() + '/CRMReports/rsviewer/reportviewer.aspx';
        form.uniquename.value = context.getOrgUniqueName();

        var query = window.location.search.substring(1);
        var vars = query.split("&");
        var idSet = false;

        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            switch (pair[0]) {
                case 'data':
                    var params = unescape(pair[1]).split("&");
                    for (var j = 0; j < params.length; j++) {
                        var param = params[j].split("=");
                        switch (param[0]) {
                            case 'id':
                                form.id.value = param[1];
                                idSet = true;
                            case 'hideparams':
                                form.PromptAreaCollapsed.value = param[1];
                            case 'iscustomreport':
                                form.iscustomreport.value = param[1];
                                // Add any other values as report parameters
                                var paramInput = document.createElement('input');
                                paramInput.setAttribute('type', 'hidden');
                                paramInput.setAttribute('name', 'p:' + param[0]);
                                paramInput.setAttribute('value', param[1]);

        if (idSet) {
        else {
            // Show message
            var dvMessage = document.createElement("div");
            dvMessage.innerHTML ="Report Id is not set";


<body onload="submitForm()">
<form action ="" method="post">
<input type="hidden" name="id" value="{xxx}" />
<input type="hidden" name="uniquename" value="" />
<input type="hidden" name="iscustomreport" value="true" />
<input type="hidden" name="reportName" value="Report Name" />
<input type="hidden" name="isScheduledReport" value="false" />
<input type="hidden" name="PromptAreaCollapsed" value="false" />

2) Include in a Dashboard or Webresource on a form using the following Web Resource Properties (The Customer Parameter Data field):

Id={xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} (make sure you add the curly braces)

You can also pass any report parameters you have by adding on :


If you want to have the report parameters hidden by default use:



So the whole data field would be something like:


I don't want to spoil all your fun – so I'll leave you to add the query to lookup the id by passing in the report name rather than the ID!

Have fun!

Comments (1) -

Pingbacks and trackbacks (5)+

Comments are closed