SrsReportRunController
controller = new SrsReportRunController();
SalesInvoiceContract
rdpContract = new SalesInvoiceContract();
SRSPrintDestinationSettings settings;
System.Byte[]
reportBytes = new System.Byte[0]();
SRSProxy
srsProxy;
SRSReportRunService
srsReportRunService = new SrsReportRunService();
Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService.ParameterValue[]
parameterValueArray;
Map
reportParametersMap;
SRSReportExecutionInfo
executionInfo = new SRSReportExecutionInfo();
;
CustInvoiceJour custInvoiceJour = CustInvoiceJour::findFromSalesId_IN("SO081204");
if(custInvoiceJour)
{
if (!WinAPI::pathExists("C:\\Temp\\Invoices\\"))
WinAPI::createDirectoryPath("C:\\Temp\\Invoices\\");
Filename filename =strfmt("C:\\Temp\\Invoices\\%1%2",custInvoiceJour.InvoiceId,".pdf");
controller.parmReportName(ssrsReportStr(SalesInvoice, Report));
controller.parmShowDialog(false);// Explicitly provide all required parameters
rdpContract.parmRecordId(custInvoiceJour.RecId);
controller.parmReportContract().parmRdpContract(rdpContract);// Change print
settings as needed
settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileFormat(SRSReportFileFormat::PDF);
settings.overwriteFile(true);
settings.fileName(filename);
controller.parmReportContract().parmReportServerConfig(SRSConfiguration::getDefaultServerConfiguration());
controller.parmReportContract().parmReportExecutionInfo(executionInfo);
srsReportRunService.getReportDataContract(controller.parmreportcontract().parmReportName());
srsReportRunService.preRunReport(controller.parmreportcontract());
reportParametersMap =
srsReportRunService.createParamMapFromContract(controller.parmReportContract());
parameterValueArray = SrsReportRunUtil::getParameterValueArray(reportParametersMap);
srsProxy = SRSProxy::constructWithConfiguration(controller.parmReportContract().parmReportServerConfig());
//
Actual rendering to byte array
reportBytes =
srsproxy.renderReportToByteArray(controller.parmreportcontract().parmreportpath(),
parameterValueArray,
settings.fileFormat(),
settings.deviceinfo());
if (reportBytes)
{
System.IO.Stream
stream = new System.IO.MemoryStream(reportBytes);
var fileStream = new System.IO.FileStream(filename, System.IO.FileMode::Create, System.IO.FileAccess::ReadWrite);
stream.CopyTo(fileStream);
}
}
==========================================================================
http://www.dnetsoft.com/en-us/d365-generate-a-report-through-x-and-save-in-a-local-folder/