You can print an existing Sales invoice to a printer through the following code, no matter how the Print Management setup of Sales Invoice might look like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
public static void printSalesInvoiceToPrinter() { SalesInvoiceController salesInvoiceController; SalesInvoiceContract salesInvoiceContract; CustInvoiceJour custInvoiceJour; SalesInvoiceJournalPrint salesInvoiceJournalPrint; SRSPrintDestinationSettings srsPrintDestSettings; DocPrintDestSettingsPrinter printerPrintDestSettings; Args args = new Args(); select firstOnly custInvoiceJour where custInvoiceJour.SalesId != ''; args.record(custInvoiceJour); salesInvoiceController = new SalesInvoiceController(); // Set the SalesInvoice.Report as SSRS Report Design. salesInvoiceController.parmReportName( PrintMgmtDocType::construct(PrintMgmtDocumentType::SalesOrderInvoice).getDefaultReportFormat()); // Set the report data contract with parameters. salesInvoiceContract = salesInvoiceController.parmReportContract().parmRdpContract(); salesInvoiceContract.parmRecordId(custInvoiceJour.RecId); // Create print destination settings. srsPrintDestSettings = new SRSPrintDestinationSettings(); // Set the selected print destination to Docentric Printer print destination. srsPrintDestSettings.printMediumType(SRSPrintMediumType::Printer_DC); printerPrintDestSettings = DocPrintDestSettingsPrinter::constructWithDefaultPrinter(); srsPrintDestSettings.parmPrinterPrintDestSettings_DC(printerPrintDestSettings); // Set print destination settings. salesInvoiceController.parmReportContract().parmPrintSettings(srsPrintDestSettings); // Initalize SalesInvoiceJournalPrint class instance because there is no other way // NOT to use the Print Management setup. salesInvoiceJournalPrint = SalesInvoiceJournalPrint::construct(); salesInvoiceJournalPrint.parmPrintFormletter(NoYes::Yes); salesInvoiceJournalPrint.parmUsePrintManagement(false); salesInvoiceJournalPrint.parmUseUserDefinedDestinations(true); salesInvoiceJournalPrint.parmPrinterSettingsFormLetter( salesInvoiceController.parmReportContract().parmPrintSettings().pack()); args.caller(salesInvoiceJournalPrint); args.parmEnumType(enumNum(PrintCopyOriginal)); args.parmEnum(PrintCopyOriginal::Original); salesInvoiceController.parmArgs(args); salesInvoiceController.parmShowDialog(false); salesInvoiceController.startOperation(); } |