07.09.2018, 12:11 | #1 |
Участник
|
dynamicsnavax: Print a report as a byte array via X++ in #MSDyn365FO
Источник: http://dynamicsnavax.blogspot.com/20...-via-x-in.html
============== In the last post I showed how to print the sales invoice as a pdf. In this post we will do the same but generate a byte array of the pdf report. I tried to make the code as readable as possible and hopefully can use it on other reports.. public static str printSalesInvoiceBase64Str(SalesInvoiceId _salesInvoiceId) { str ret; CustInvoiceJour custInvoiceJour; select firstonly custInvoiceJour where custInvoiceJour.InvoiceId == _salesInvoiceId; if (custInvoiceJour) { str ext = SRSPrintDestinationSettings::findFileNameType(SRSReportFileFormat::PDF, SRSImageFileFormat::BMP); PrintMgmtReportFormatName printMgmtReportFormatName = PrintMgmtDocType::construct(PrintMgmtDocumentType::SalesOrderInvoice).getDefaultReportFormat(); SalesInvoiceContract salesInvoiceContract = new SalesInvoiceContract(); salesInvoiceContract.parmRecordId(custInvoiceJour.RecId); SrsReportRunController srsReportRunController = new SrsReportRunController(); srsReportRunController.parmReportName(printMgmtReportFormatName); srsReportRunController.parmExecutionMode(SysOperationExecutionMode::Synchronous); srsReportRunController.parmShowDialog(false); srsReportRunController.parmReportContract().parmRdpContract(salesInvoiceContract); srsReportRunController.parmReportContract().parmReportExecutionInfo(new SRSReportExecutionInfo()); srsReportRunController.parmReportContract().parmReportServerConfig(SRSConfiguration::getDefaultServerConfiguration()); SRSPrintDestinationSettings printerSettings = srsReportRunController.parmReportContract().parmPrintSettings(); printerSettings.printMediumType(SRSPrintMediumType::File); printerSettings.fileFormat(SRSReportFileFormat::PDF); printerSettings.parmFileName(custInvoiceJour.InvoiceId + ext); printerSettings.overwriteFile(true); SRSReportRunService srsReportRunService = new SrsReportRunService(); srsReportRunService.getReportDataContract(srsReportRunController.parmReportContract().parmReportName()); srsReportRunService.preRunReport(srsReportRunController.parmReportContract()); Map reportParametersMap = srsReportRunService.createParamMapFromContract(srsReportRunController.parmReportContract()); Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService.ParameterValue[] parameterValueArray = SrsReportRunUtil::getParameterValueArray(reportParametersMap); SRSProxy srsProxy = SRSProxy::constructWithConfiguration(srsReportRunController.parmReportContract().parmReportServerConfig()); System.Byte[] reportBytes = srsproxy.renderReportToByteArray(srsReportRunController.parmreportcontract().parmreportpath(), parameterValueArray, printerSettings.fileFormat(), printerSettings.deviceinfo()); if (reportBytes) { using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(reportBytes)) { ret = System.Convert::ToBase64String(memoryStream.ToArray()); } } } return ret; } Printing the byte array string as an info log looks like this. To test the encoding and decoding, I have used online tools like this: https://www.freeformatter.com/base64-encoder.html Other sources for your reference: https://meritsolutions.com/render-re...-d365-aka-ax7/ https://d365technext.blogspot.com/20...nt-d365fo.html I will continue this series of posts to some exciting capabilities. Until next time, enjoy. Источник: http://dynamicsnavax.blogspot.com/20...-via-x-in.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|
|
|