Hey - i am trying to print a report to a PDF file in a local directory.
There are many working examples for AX2012 and if you copy the code everything is working except that ax downloads the PDF in the Browser instead of saving a PDF in a directory.
My goal is to stream a SalesInvoice Report via webserivce.
What we used to do in 2012:
1) generate the Report and save it t c:\temp\xyz.pdf
2) read the file and pass the content to the AIF
3) delete the file
The used code is not working anymore in AX 365 - it keeps telling me that the file does not exist.
So I created a runnable class:
class TestPrintJob
{
/// <summary>
/// Runs the class with the specified arguments.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
Args args;
ContactPerson contactPerson;
SrsReportRunController controller;
SRSPrintDestinationSettings srsPrintDestinationSettings;
CustTable custTable;
CustInvoiceJour custInvoiceJour = custInvoiceJour::findRecId(5637163320);
SalesTable salesTable;
SalesInvoiceContract rdpContract;
System.Byte[] pdfDocBuffer;
System.IO.FileInfo fi_pdfDoc;
System.IO.FileStream fs;
guid myGuid;
str pdfString = '',
savedFile,
filePath,
myGuidStr,
reportPath;
if (custInvoiceJour.RecId != 0)
{
myGuid = newguid();
myGuidStr = guid2str(myGuid);
controller = new SrsReportRunController();
controller.parmReportName(ssrsReportStr(SalesInvoice, Report));
controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
controller.parmShowDialog(false);
controller.objectOnServer();
rdpContract = new SalesInvoiceContract();
rdpContract.parmRecordId(custInvoiceJour.RecId);
rdpContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo());
rdpContract.parmDocumentTitle("@SYS14204");
// (1) Try by passing args
args = new Args();
args.record(custInvoiceJour);
args.parmEnum(PrintCopyOriginal::OriginalPrint);
args.parmEnumType(enumNum(PrintCopyOriginal));
controller.parmReportContract().parmRdpContract(rdpContract);
controller.parmArgs(args);
// Change print settings as needed
srsPrintDestinationSettings = controller.parmReportContract().parmPrintSettings();
srsPrintDestinationSettings.printMediumType(SRSPrintMediumType::Custom);
srsPrintDestinationSettings.fileFormat(SRSReportFileFormat::PDF);
srsPrintDestinationSettings.overwriteFile(true);
filePath = @'c:\tmp\InvoiceReport_' + myGuidStr + '.pdf';
srsPrintDestinationSettings.fileName(filePath);
controller.startOperation();
}
}
}
If I run the job AX is rendering the Report and it gets downloaded instantly while C:\tmp stays empty.
I cant figure out why the old way is not working anymore.
Is there any way to save the report to a file or in a string?
Thanks in advance - Alex