So, there are many times when we have to display a report, mostly a SSRS report on dashboard tiles. This is quite easy by using a html weberesource. But at times we will have to set the parameters by default. Today I came across one such scenario and thought it would be quite useful to share.
Requirement: Show a SSRS report on the dashboard and set the default parameters by passing from dashboard.
Prerequisite: Create the required SSRS report and add parameters. Don’t set any default value for the parameters. Now follow the steps.
Step 1: Create a HTML web resource as shown below
<html>
<head>
http://ClientGlobalContext.js.aspx
var CRMCustomParameters = [];
CRMCustomParameter = GetParameters();
function GetParameters () {
var Parameters = GetGlobalContext().getQueryStringParameters();
if (typeof Parameters !== “undefined”) {
CRMCustomParameters = ParseParameters(Parameters.data);
}
}
function ParseParameters(Query) {
var ResultParameters = {};
if (Query != undefined && Query != null) {
var QuerySplit = Query.split(“&”);
for (var i = 0; i 1 ? ParameterPair[1] : null;
}
}
return ResultParameters;
}
function SetReport() {
var id = CRMCustomParameters.guid; //Guid of Report
var param1 = CRMCustomParameters.parameter1; //First Filter Parameter
var param2 = CRMCustomParameters.parameter2; //Second Filter Parameter
var serverAndOrgUrl = getServerUrl();
var iframeSrc = serverAndOrgUrl + ‘/crmreports/viewer/viewer.aspx?action=run&id=%7b’ + id + ‘%7d&p:ReportParameter1=’ + param1 + ‘&p:ReportParameter2=’ + param2;
var report = document.createElement(“iframe”);
report.setAttribute(‘id’, ‘reportFrame’);
report.setAttribute(‘name’, ‘reportFrame’);
report.setAttribute(‘src’, iframeSrc);
report.setAttribute(‘height’, ‘100%’);
report.setAttribute(‘width’, ‘100%’);
report.setAttribute(‘scrolling’, ‘auto’);
report.setAttribute(‘frameborder’, ‘0’);
var reportDiv = document.createElement(“div”);
reportDiv.setAttribute(‘height’, ‘100%’);
reportDiv.setAttribute(‘width’, ‘100%’);
reportDiv.appendChild(report);
document.body.appendChild(reportDiv);
function getServerUrl() {
context = GetGlobalContext();
return context.getClientUrl();
}
}
<meta><style type=”text/css”></style><meta><style type=”text/css”>
P {
margin: 0;
}
</style><meta><style type=”text/css”>
P {
margin: 0;
}
</style><meta><style type=”text/css”>
P {
margin: 0;
}
</style><meta><style type=”text/css”>
P {
margin: 0;
}
</style><meta><style type=”text/css”>
P {
margin: 0;
}
</style><meta><style type=”text/css”>
P {
margin: 0;
}
</style><meta><style type=”text/css”>
P {
margin: 0;
}
</style><meta><style type=”text/css”>
P {
margin: 0;
}
</style>
</head>
<body style=”margin: 0px; word-wrap: break-word;” onload=”SetReport()” onfocusout=”parent.setEmailRange();”></body>
</html>
Step 2: Create the dashboard and add the html webresource to dashboard. Then pass the parameters as shown in below fig
Note: The code above is a generic one and only one parameter is passed in the fig (other than guid).
There you go!!! Now we can see the report in dashboard.
Explanation:
1. GetParameters function retrieve the parameters to the variable CRMCustomParameters.
2. SetReport function sets the report in dashboard.
Hope it helps!!
Hi,
can you please elaborate on how to get the GUID of the report? All our SSRS reports are accessed via the URL like this:
http://servername/Reports_SQTP1/Pages/Report.aspx?ItemPath=/Reports/Administration/General+Administration/ADM002
This works when pasted into a browser on its own, but not when we put into an iframe in CRM due to scripts being disabled. Hence why we need the Web Resource Solution you’ve outlined.
Hi Rodney,
Apologies for delayed response.
For getting guid, go to reports and open the report in a new window. This will give you a url with guid – this worked for me in online. Hope it will work for on premise also. If it’s not working, you can get the guid from reporting server. Hope it helps!!