MobileCRM.UI.ReportForm.show - Resconet/JSBridge GitHub Wiki

Shows the Dynamics CRM report form.

Arguments

Argument Type Description
success function(obj) The callback function that is called if the report form was successfully opened.
failed function(errorMsg) The errorCallback which is called asynchronously in case of error.
scope Object The scope for callbacks.

This example demonstrates how to open the report form with reports in specified languages and pre-select one of them.

var reportForm = new MobileCRM.UI.ReportForm();
reportForm.allowedLanguages = [-1, 1033, 1031]; // Allow "Any language", English and German reports only
reportForm.defaultReport = "Default"; // Pre-select the report with the name "Default"
reportForm.show(null, MobileCRM.bridge.alert); // Do nothing on success, say error on failure

This example demonstrates how to implement custom command for opening specific set of reports for current entity.

// Register command handler for custom command which was appended to form in Woodford
MobileCRM.UI.EntityForm.onCommand("custom_PrintReport", function (entityForm) {
	fetchReports(3); // 3 is object type code for Opportunity entity (for demonstration)
}, true);
function fetchReports(objectTypeCode) {
	// fetch desired reports - Requires "Report" entity being enabled in Woodford!!!
	var entity = new MobileCRM.FetchXml.Entity("report");
	entity.addAttribute("reportid");
	var filter = entity.addFilter();
	filter.where("parentreportid", "null", null); // take just root reports
	// link reportentity filtering just reports for our object type code (Opportunity)
	var linkEntity = entity.addLink("reportentity", "reportid", "reportid", "inner");
	linkEntity.addFilter().where("objecttypecode", "eq", objectTypeCode);
	// Take only reports owned by our business unit (optional)
	linkEntity = entity.addLink("businessunit", "businessunitid", "owningbusinessunit", "inner");
	linkEntity.addFilter().where("businessunitid", "eq-businessid", null);
	// TBD: Optionally define order: entity.orderBy("name", false);
	// Execute online fetch request
	var fetch = new MobileCRM.FetchXml.Fetch(entity);
	fetch.executeOnline("Array", // Take the results as an array of arrays with field values
	function (result) {
		// "result" is array of arrays [id1],[id2],...[idn](/Resconet/JSBridge/wiki/id1],[id2],...[idn)
		var ids = [];
		for (var i in result) {
			var record = result[i];
			ids.push(record[0]); // take just first (and only) field which is reportid
		}
		showReport(ids);
	}, function (err) {
		MobileCRM.bridge.alert("Error fetching accounts: " + err);
	}, null);
}
function showReport(ids) {
	var reportForm = new MobileCRM.UI.ReportForm();
	reportForm.allowedReportIds = ids;
	//reportForm.defaultReport = "Default";			// Optionally pre-select the report with the name "Default"
	reportForm.show(null, MobileCRM.bridge.alert); // Do nothing on success, say error on failure
}