Can somebody tell me what am I missing in this code? I'm creating salesInvoices yet the invoices do not have the title parameters so I'm missing data. instead of "Invoice No. 1234" i have only "No. 1234" like the documentTitle() is not involved in this, and the second thing all invoices are created in my local language there is no translation like when I print it normally from AX form using PrintOriginal etc.
public void saveSalesInvoiceToPdfFile(RecId _refRecId)
{
if (_refRecId)
{
PrintMgmtReportFormatName printMgmtReportFormatName = PrintMgmtDocType::construct(PrintMgmtDocumentType::SalesOrderInvoice).getDefaultReportFormat();
SalesInvoiceContract salesInvoiceContract = new SalesInvoiceContract();
salesInvoiceContract.parmRecordId(_refRecId);
SalesInvoiceController SalesInvoiceController = SalesInvoiceController::construct();
SalesInvoiceController.parmReportName(printMgmtReportFormatName);
SalesInvoiceController.parmExecutionMode(SysOperationExecutionMode::Synchronous);
SalesInvoiceController.parmShowDialog(false);
SalesInvoiceController.parmReportContract().parmRdpContract(salesInvoiceContract);
SalesInvoiceController.parmReportContract().parmReportExecutionInfo(new SRSReportExecutionInfo());
SalesInvoiceController.parmReportContract().parmReportServerConfig(SRSConfiguration::getDefaultServerConfiguration());
var args = new Args();
args.parmEnum(PrintCopyOriginal::Original);
args.record(custInvoiceJour::findRecId(_refRecId));
SalesInvoiceController.parmArgs(args);
SRSPrintDestinationSettings printerSettings = SalesInvoiceController.parmReportContract().parmPrintSettings();
printerSettings.printMediumType(SRSPrintMediumType::File);
printerSettings.fileFormat(SRSReportFileFormat::PDF);
printerSettings.parmFileName(filePath fileName);
printerSettings.overwriteFile(true);
SRSReportRunService srsReportRunService = new SrsReportRunService();
srsReportRunService.getReportDataContract(SalesInvoiceController.parmReportContract().parmReportName());
srsReportRunService.preRunReport(SalesInvoiceController.parmReportContract());
Map reportParametersMap = srsReportRunService.createParamMapFromContract(SalesInvoiceController.parmReportContract());
Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService.ParameterValue[] parameterValueArray = SrsReportRunUtil::getParameterValueArray(reportParametersMap);
SRSProxy srsProxy = SRSProxy::constructWithConfiguration(SalesInvoiceController.parmReportContract().parmReportServerConfig());
System.Byte[] reportBytes = srsproxy.renderReportToByteArray(SalesInvoiceController.parmreportcontract().parmreportpath(), parameterValueArray, printerSettings.fileFormat(), printerSettings.deviceinfo());
if (reportBytes)
{
System.IO.Stream stream = new System.IO.MemoryStream(reportBytes);
System.IO.FileStream fileStream = new System.IO.FileStream(filePath fileName, System.IO.FileMode::Create, System.IO.FileAccess::ReadWrite);
stream.CopyTo(fileStream);
fileStream.Close();
}
}
}