Reputation: 69
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();
Upvotes: 2
Views: 2822
Reputation: 18051
I have done a similar on sales confirm on AX 2012, except this works :)
The method was on the CustComfirmJour table, so this
refers to a confirmed record.
FileName saveAs(FileName fileName)
{
SalesConfirmController salesConfirmController;
SalesConfirmContract salesConfirmContract;
SRSPrintDestinationSettings printSettings;
Args args = new Args();
;
args.record(this);
salesConfirmController = new SalesConfirmController();
salesConfirmController.parmReportName(ssrsReportStr(SalesConfirm,Report));
salesConfirmController.parmArgs(args);
salesConfirmController.parmReportContract().parmRdlContract().parmLanguageId(this.LanguageId);
salesConfirmContract = salesConfirmController.parmReportContract().parmRdpContract();
salesConfirmContract.parmRecordId(this.RecId);
printSettings = salesConfirmController.parmReportContract().parmPrintSettings();
printSettings.printMediumType(SRSPrintMediumType::File);
printSettings.overwriteFile(true);
printSettings.fileFormat(SRSReportFileFormat::PDF);
fileName = printSettings.fileName(fileName);
salesConfirmController.runReport();
return fileName;
}
This will not work in AX 2009.
Here your approach as documented in Axaptapedia should work but don't!
FileName saveAs(FileName fileName)
{
ReportRun report;
PrintJobSettings printSettings;
Args args = new Args(reportStr(SalesConfirm));
;
args.record(this);
report = classfactory.reportRunClass(args);
report.init();
printSettings = report.printJobSettings();
printSettings.setTarget(PrintMedium::File);
printSettings.preferredTarget(PrintMedium::File);
printSettings.format(PrintFormat::PDF);
printSettings.preferredFileFormat(PrintFormat::PDF);
printSettings.fileName(fileName);
printSettings.lockDestinationProperties(true); //Did the trick!?!
report.unpackPrintJobSettings(printSettings.packPrintJobSettings());
report.run();
return fileName;
}
To run:
static void SalesConfirmSaveAs(Args _args)
{
CustConfirmJour jour;
select firstonly jour;
jour.saveAs(@"V:\Temp\confirm.pdf");
}
The output goes to screen!
Maybe the report itself is messing up?
Update: added printSettings.lockDestinationProperties(true);
but haven't tested yet.
Upvotes: 0
Reputation: 2354
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.
Upvotes: 4