Archive
Pass parameters to the report hosted in IFrame or Web Page
Hi,
Assume you have to display related ‘contacts’ of an ‘Account’ in the report hosted in an IFrame.
You can prepare a dataset using below query in the report
SELECT * FROM FilteredContact C
WHERE
C.accountid=@CRM_AccountId
To set parameter ‘@CRM_AccountId‘, you can pass parameter in the URL in this format "&p:CRM_AccountId="
={Account GUID}"
Sample URL
var url = Xrm.Page.context.getServerUrl() + “/crmreports/viewer/viewer.aspx?action=run&context=records&helpID=Internal%20Call%20Report.rdl&id=%7bcd80109a-dc7c-e111-a040-00155dc87c64%7d&records=%7b245DB4C3-927C-E111-9FA1-00155DC87C64%7d&recordstype=1+ “&p: CRM_AccountId=” + accountId;
Below is the useful article explained in detail
Hope it helps 🙂
Opening a report using ribbon button in CRM 2011
Hi,
To open the Report :-
- We need report GUID and report associated entity record GUID
- Get report GUID by using ‘Report Name’ using ‘retrieveMultiple’ function
- Prepare URl and open new window
Below are the functions
function openReport (reportName) {
var oDataSetName = “ReportSet”;
var columns = “ReportId”;
var filter = “Name eq ‘” + reportName + “‘”;
retrieveMultiple(oDataSetName, columns, filter, onSuccess);
currReportName = reportName;
}
var currReportName;
function onSuccess (data, textStatus, XmlHttpRequest) {
var serverUrl = Xrm.Page.context.getServerUrl();
if (data && data.length > 0) {
var serverUrl = Xrm.Page.context.getServerUrl();
var id = Xrm.Page.data.entity.getId();
var etc = Xrm.Page.context.getQueryStringParameters().etc;
var callReportId = id.replace(‘{‘, ”).replace(‘}’, ”);
var reportId = data[0].ReportId.replace(‘{‘, ”).replace(‘}’, ”);
var url = serverUrl + “/crmreports/viewer/viewer.aspx?action=run&context=records&helpID=” + currReportName + “.rdl&id=%7b” + reportId + “%7d&records=%7b” + callReportId + “%7d&recordstype=” + etc;
window.open(url, “reportwindow”, “resizable=1,width=950,height=700”);
}
}
function retrieveMultiple(odataSetName, select, filter, successCallback) {
var serverUrl = Xrm.Page.context.getServerUrl();
var ODATA_ENDPOINT = “/XRMServices/2011/OrganizationData.svc”;
var odataUri = serverUrl + ODATA_ENDPOINT + “/” + odataSetName + “?”;
if (select) {
odataUri += “$select=” + select + “&”;
}
if (filter) {
odataUri += “$filter=” + filter;
}
$.ajax({
type: “GET”,
contentType: “application/json; charset=utf-8”,
datatype: “json”,
url: odataUri,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader(“Accept”, “application/json”);
},
success: function (data, textStatus, XmlHttpRequest) {
if (successCallback) {
if (data && data.d && data.d.results) {
successCallback(data.d.results, textStatus, XmlHttpRequest);
}
else if (data && data.d) {
successCallback(data.d, textStatus, XmlHttpRequest);
}
else {
successCallback(data, textStatus, XmlHttpRequest);
}
}
},
error: function (XmlHttpRequest, textStatus, errorThrown) {
if (XmlHttpRequest && XmlHttpRequest.responseText) {
alert(“Error while retrieval ; Error – ” + XmlHttpRequest.responseText);
}
}
});
}
- Create a new .Jscript file and copy above functions
- Replace double quotes & single quote symbols with keyboard symbols
- Add the .jscript as web resource
- Add “json” & “jquery” helper scripts as web resources
How Do I call these methods :-
- Assume you have a report named “My Account Report” associated (i.e., Related Record Types) to “Account” entity
- Place a ribbon button on account entity form
- Call openReport(“My Account Report”) function from ribbon button (How to call function from ribbon button)
Hope it helps 🙂