D365 - Generate A Report Through X++ and Save in A Local Folder
D365 - Generate A Report Through X++ and Save in A Local Folder
I've taken the example of sales invoice, the following code will download the sales order
invoice automatically and save the PDF file in the specified path.
if ( _custInvoiceJour)
{
if (!WinAPI::pathExists("C:\\Temp\\Invoices\\"))
WinAPI::createDirectoryPath("C:\\Temp\\Invoices\\");
filename
=strfmt('C:\\Temp\\Invoices\\%1%2',_custInvoiceJour.InvoiceId,".pdf");
controller.parmReportName(ssrsReportStr(SalesInvoic, ReportTH));
controller.parmShowDialog(false);
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);