2

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();
AX_Dev
  • 69
  • 1
  • 4
  • 11

2 Answers2

4

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.

AnthonyBlake
  • 2,334
  • 1
  • 25
  • 39
0

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.

Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50
  • I'm very confident it is the report. The fetch method is being used to accommodate print settings per AX 2009 report. In particular, the following code statement makes me believe the print settings I'm supplying are being discarded. salesFormLetterReport.loadPrintSettings( custQuotationJour, salesQuotationTable, custQuotationJour.LanguageId); I think this is the case, but I'm not seeing it when I debug. I'm wnodering if there is a means of letting the report know to keep my settings instead. – AX_Dev Jun 03 '13 at 17:59
  • 1
    try adding 'printSettings.lockDestinationProperties(true);' which may prevent the report itself from overriding print settings – AnthonyBlake Jun 05 '13 at 09:19
  • I appreciate both of your efforts, thank you very much. @AnthonyBlake As soon as I added that it worked and created the PDF file. This definitely made my day. Wish there was a way I could mark the comment as an answer. – AX_Dev Jun 05 '13 at 12:31