Search code examples
axaptadynamics-ax-2009ax

Print Sales Quotation report to PDF AX 2009


I am currently on AX 2009 SP1 Rollup 7. I am attempting to create a PDF when my method is ran sending a quotation Id from the CustQuotationJour table to the SalesQuotation report.

The method works OK, but the report is sent to the Print Preview screen instead of creating a PDF. I assume its SalesQuotation report resetting my print setting reverting back to screen. My guess is within the fetch method, but I shouldn't have to modify this, right?

Is there another print setting that I may be missing? Thanks in advance

ReportRun                   salesQuotationReport;
Args                        args = new Args();
PrintJobSettings            printJobSettings;
CustQuotationJour           custQuotationJour;
;

custQuotationJour = CustQuotationJour::findFromSalesQuotationQuotation(_quotationId);


args.name(reportStr(SalesQuotation));
args.record(custQuotationJour);
salesQuotationReport = new ReportRun(args);
salesQuotationReport.init();

printJobSettings = salesQuotationReport.printJobSettings();
printJobSettings.setTarget(PrintMedium::File);
printJobSettings.preferredTarget(PrintMedium::File);
printJobSettings.format(PrintFormat::PDF);
printJobSettings.preferredFileFormat(PrintFormat::PDF);
printJobSettings.fileName(_path);

salesQuotationReport.unpackPrintJobSettings(printJobSettings.packPrintJobSettings());
salesQuotationReport.run();

Solution

  • So here's my comment converted into an answer...

    Add the following line;

    printSettings.lockDestinationProperties(true);

    This will prevent any code within the report from overriding your printSettings.