MobileCRM.MobileReport.generateReportAsync - Resconet/JSBridge GitHub Wiki

[v18.0] Generates the mobile report based on provided request parameters. The generated report will be saved to file system or attached to a record.

Arguments

Argument Type Description
request MobileCRM.MobileReport.GenerateReportRequest The request specifying the details of how the report will be created.

This example demonstrates how to make a custom form command to generate mobile report from currently opened account record and save the report as account's annotation.

MobileCRM.UI.EntityForm.onCommand(
  "custom_run_account_report", // this custom command must be configured in Woodford
  async function (entityForm) {
	try {
	  const request = new MobileCRM.MobileReport.GenerateReportRequest();
	  request.source = new MobileCRM.Reference(entityForm.entity.entityName, entityForm.entity.id); // you can also use xml fetch here
	  request.template = "Account Report"; // you can also use ID or xml fetch here
	  request.format = "Pdf";
	  request.customNameOrPath = "My Account Report";
	  request.waitMessage = "Generating report, please wait."; // you can use "" to disable wait message, or undefined to show default system message.
	  request.attachTo = request.source;
	  // generate the report
	  const result = await MobileCRM.MobileReport.generateReportAsync(request);
	  MobileCRM.bridge.alert("Report generated succesfully and saved to " + result.attachmentRecord.primaryName + " (" + result.attachmentRecord.entityName + ").");
	  // open the created report from database
	  MobileCRM.UI.FormManager.showEditDialog(result.attachmentRecord.entityName, result.attachmentRecord.id);
	} catch (e) {
	  MobileCRM.bridge.alert("Failed to generate report. \n\n" + e);
	}
  },
  true,
  null
);

This example demonstrates how to make a custom questionnaire command to create questionnaire report in currently selected language and attach it to questionnaire.

MobileCRM.UI.QuestionnaireForm.onCommand(
"custom_run_report",
async function (form) {
  try {
	var questionnaireLanguageCode = form.language;
	var questionnaire = form.questionnaire;
	const request = new MobileCRM.MobileReport.GenerateReportRequest();
	request.source = new MobileCRM.Reference(
	  questionnaire.entityName,
	  questionnaire.id
	);
	request.template = undefined; // this will use default questionnaire template
	request.format = "Pdf";
	request.languageCode = questionnaireLanguageCode;
	request.customNameOrPath = questionnaire.primaryName + " Report";
	request.waitMessage = "Generating report, please wait.";
	request.attachTo = request.source;
	const result = await MobileCRM.MobileReport.generateReportAsync(request);
	MobileCRM.bridge.alert("Report generated succesfully and saved to " + result.attachmentRecord.primaryName + " (" + result.attachmentRecord.entityName + ").");
	MobileCRM.UI.FormManager.showEditDialog(
	  result.attachmentRecord.entityName,
	  result.attachmentRecord.id
	);
  } catch (e) {
	MobileCRM.bridge.alert("Failed to generate report. \n\n" + e);
  }
},
true
	  );

This example demonstrates how to make a custom form command to export currently opened account record to excel file.

MobileCRM.UI.EntityForm.onCommand(
  "custom_export_account_report", // this custom command must be configured in Woodford
  async function (entityForm) {
	try {
	  const request = new MobileCRM.MobileReport.GenerateReportRequest();
	  request.source = new MobileCRM.Reference(entityForm.entity.entityName, entityForm.entity.id);
	  request.template = undefined; // this will use default export template
	  request.format = "Excel"; // you can also use "Pdf" or other format to have tabular report in a document.
	  request.customNameOrPath = "My Account Report";
	  request.waitMessage = "Generating report, please wait.";
	  const result = await MobileCRM.MobileReport.generateReportAsync(request);
	  MobileCRM.bridge.alert("Report generated succesfully in " + result.outputReportPath);
	} catch (e) {
	  MobileCRM.bridge.alert("Failed to generate report. \n\n" + e);
	}
  },
  true,
  null
);