AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 07.09.2018, 12:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,459 / 846 (79) +++++++
Регистрация: 28.10.2006
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, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
dynamicsnavax: Print a Sales Invoice via X++ in #MSDyn365FO Blog bot DAX Blogs 0 04.09.2018 22:15
NAV Team: Report Execution Insights Blog bot Dynamics CRM: Blogs 0 30.10.2014 15:02
ax-erp: Walkthrough: Creating a Report Bound to a Report Data Provider Class (X++ Business Logic) [AX 2012] Blog bot DAX Blogs 0 20.09.2012 11:11
emeadaxsupport: New Content for Microsoft Dynamics AX 2012 : October 2011 Blog bot DAX Blogs 0 27.10.2011 17:11
wiki.dynamicsbook: Changes Made in Navision Attain 3.60 Blog bot Dynamics CRM: Blogs 0 02.09.2008 13:23
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 02:27.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.