Axaptapedia is now maintained by AgileCadence For more information please click here.

Talk:Printer Settings and Run From Code

From Axaptapedia
Jump to: navigation, search

This is all very well, if you only wish to print some reports from code in Dynamics AX 2009. However, this will not cover the problems encountered if you wish to do the same with FormLetter Reports.

Axel Kühn covers this very well in the following Article:

[1]

Here though, Axel only covers an example where the printing of the FormLetter is preceeded by code which posts the Journal.

If you wish to Print FormLetters from code irrespective of the posting, then you need to understand the use of the Enumerator PrintCopyOriginal.

Only PrintCopyOriginal::OriginalPrint will suffice to keep your Report off the screen! You can include this in the arg's ParmEnum parameter.

And it looks like this:

<xpp> public void WhatEverMethod(Common common) {

   SalesFormLetter     salesFormLetter;
   ReportRun           custReport;
   Args                args = new Args();
   PrintJobSettings    printJobSettings;
   ;
   salesFormLetter = new SalesFormLetter_Invoice();
   args.name(reportStr(SalesInvoice));
   args.caller(salesFormLetter);
   args.record(common);
   args.parmEnum(PrintCopyOriginal::OriginalPrint);
   custReport = new ReportRun(args);
   custReport.query().interactive(false);
   custReport.report().interactive(false);
   printJobSettings = custReport.printJobSettings();
   printJobSettings.setTarget(PrintMedium::File);
   printJobSettings.preferredTarget(PrintMedium::File);
   printJobSettings.format(PrintFormat::PDF);
   printJobSettings.preferredFileFormat(PrintFormat::PDF);
   printJobSettings.fileName(@"C:\\test-invoice.pdf");
   salesFormLetter.updatePrinterSettingsFormLetter(printJobSettings.packPrintJobSettings());
   custReport.init();
   custReport.run();

} </xpp>