I'm trying to save a Sales Invoice PDF automatically when the user creates an invoice. When the user clicks the create button, the invoice will be created and, at the same time, it will be save as a PDF in a path. The problem I'm facing is that the PDF is saved in blank and whenever I execute the code, AX stops working. This is what I have until now:
public void savePDFInServer(CustInvoiceJour custInvoiceJour, TaxTypeDocumentId taxTypeDocumentId, InvoiceDate invoiceDate)
{
PrintMgmtReportFormatName printMgmtReportFormatName;
SRSPrintDestinationSettings settings;
SrsReportRunController controller = new SrsReportRunController();
PurchPurchaseOrderContract rdpContract = new PurchPurchaseOrderContract();
SalesInvoiceContract salesInvoiceContract = new SalesInvoiceContract();
controller.parmReportName(printMgmtReportFormatName);
controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
rdpContract.parmRecordId(custInvoiceJour.RecId);
controller.parmReportContract().parmRdpContract(rdpContract);
salesInvoiceContract.parmRecordId(custInvoiceJour.RecId);
controller.parmReportContract().parmRdpContract(salesInvoiceContract);
salesInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo());
settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileFormat(SRSReportFileFormat::PDF);
settings.overwriteFile(true);
settings.fileName(@'C:\Users\spineda\Desktop\Prueba.pdf');
controller.parmShowDialog(false);
controller.startOperation();
}
After checking the code, I realized that the problem was that the record was not saved in the table and when it tried to save the pdf, the record was not commited. What I did is that I made sure that the record was saved in the table and then I generated the pdf.