Dynamics AX Blog - Page 15
Post sales invoice through codeWith the help of the following lines, I want to show how you can post a sales invoice by code. static void postSalesInvoice(Args _args) { SalesTable salesTable = SalesTable::find("000747"); SalesFormLetter salesFormLetter; salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice); salesFormLetter.update(salesTable, systemDateGet(), SalesUpdate::All); } |
Print packing slip through codeThe following job demonstrates, how you can print an existing Sales packing slip through code. The example sends the report to screen. static void printSalesPackingSlipThroughCode(Args _args) { SalesPackingSlipJournalPrint salesPackingSlipJournalPrint; Set set = new Set(Types::Record); SRSPrintDestinationSettings srsPrintDestinationSettings; // Add record set.add(CustPackingSlipJour::findRecId(5637161120)); // Set printer settings srsPrintDestinationSettings = new SRSPrintDestinationSettings(); srsPrintDestinationSettings.fileFormat(SRSReportFileFormat::Screen); // Initalize salesPackingSlipJournalPrint = SalesPackingSlipJournalPrint::construct(); salesPackingSlipJournalPrint.parmPrintFormletter(NoYes::Yes); salesPackingSlipJournalPrint.parmUsePrintManagement(false); salesPackingSlipJournalPrint.parmPrinterSettingsFormLetter(srsPrintDestinationSettings.pack()); // Print salesPackingSlipJournalPrint.printJournal(set); } Changing the parameter of the instance of SRSPrintDestinationSettings allows you to send the sales packing slip to printer, file or mail. The next example creates a PDF-file. static void printSalesPackingSlipThroughCode(Args _args) { SalesPackingSlipJournalPrint salesPackingSlipJournalPrint; Set set = new Set(Types::Record); SRSPrintDestinationSettings srsPrintDestinationSettings; // Add record set.add(CustPackingSlipJour::findRecId(5637161120)); // Set printer settings srsPrintDestinationSettings = new SRSPrintDestinationSettings(); srsPrintDestinationSettings.fileFormat(SRSReportFileFormat::PDF); srsPrintDestinationSettings.fileName(@'c: emppackingslip.pdf'); srsPrintDestinationSettings.printMediumType(SRSPrintMediumType::File); srsPrintDestinationSettings.numberOfCopies(1); srsPrintDestinationSettings.overwriteFile(true); // Initalize salesPackingSlipJournalPrint = SalesPackingSlipJournalPrint::construct(); salesPackingSlipJournalPrint.parmPrintFormletter(NoYes::Yes); salesPackingSlipJournalPrint.parmUsePrintManagement(false); salesPackingSlipJournalPrint.parmPrinterSettingsFormLetter(srsPrintDestinationSettings.pack()); // Print salesPackingSlipJournalPrint.printJournal(set); } If you want to print multiple sales confirmations at once, you have to add the corresponding CustPackingSlipJour-records to the set called "set: ... // Add record set.add(CustPackingSlipJour::findRecId(5637155842)); set.add(CustPackingSlipJour::findRecId(5637145354)); ... To additionally save the sales packing slip to print archive, you can add the following line: ... srsPrintDestinationSettings.parmPrintToArchive(true); ... |
Create primary address through codeThe following lines show an example of how you can create a (primary) address for an existing party in the global address book by x ++ code. static void createPartyAddress(Args _args) { DirPartyTable dirPartyTable = DirPartyTable::findByNum("???100000"); DirParty dirParty; DirPartyPostalAddressView dirPartyPostalAddressView; // Create instance of dirParty dirParty = DirParty::constructFromCommon(dirPartyTable, DirUtility::getCurrentDateTime(), dirPartyTable.partyType()); // Create primary address dirPartyPostalAddressView.LocationName = "Office"; dirPartyPostalAddressView.City = "Vienna"; dirPartyPostalAddressView.Street = "Kärtnerring"; dirPartyPostalAddressView.StreetNumber = "18"; dirPartyPostalAddressView.CountryRegionId = "AUT"; dirPartyPostalAddressView.IsPrimary = NoYes::Yes; dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView); } |
Print sales confirmation through codeThe following job demonstrates, how you can print an existing Sales confirmation through code. The example sends the report to screen. static void printSalesConfirmThroughCode(Args _args)
{ SalesConfirmJournalPrint salesConfirmJournalPrint; Set set = new Set(Types::Record); SRSPrintDestinationSettings srsPrintDestinationSettings; // Add record set.add(CustConfirmJour::findRecId(5637155842)); // Set printer settings srsPrintDestinationSettings = new SRSPrintDestinationSettings(); srsPrintDestinationSettings.fileFormat(SRSReportFileFormat::Screen); // Initalize salesConfirmJournalPrint = SalesConfirmJournalPrint::construct(); salesConfirmJournalPrint.parmPrintFormletter(NoYes::Yes); salesConfirmJournalPrint.parmUsePrintManagement(false); salesConfirmJournalPrint.parmPrinterSettingsFormLetter(srsPrintDestinationSettings.pack()); salesConfirmJournalPrint.printJournal(set); } |
Print purchase order through codeThe following job demonstrates, how you can print an existing Purchase order through code. The example sends the report to screen. static void printPurchaseOrderThroughCode(Args _args)
{ PurchPurchOrderJournalPrint purchPurchOrderJournalPrint; Set set = new Set(Types::Record); SRSPrintDestinationSettings srsPrintDestinationSettings; // Add record set.add(VendPurchOrderJour::findRecId(5637179849)); // Set printer settings srsPrintDestinationSettings = new SRSPrintDestinationSettings(); srsPrintDestinationSettings.fileFormat(SRSReportFileFormat::Screen); // Initalize purchPurchOrderJournalPrint = PurchPurchOrderJournalPrint::construct(); purchPurchOrderJournalPrint.parmPrintFormletter(NoYes::Yes); purchPurchOrderJournalPrint.parmUsePrintManagement(false); purchPurchOrderJournalPrint.parmPrinterSettingsFormLetter(srsPrintDestinationSettings.pack()); purchPurchOrderJournalPrint.printJournal(set); } |
Print sales invoice through codeThe following job demonstrates, how you can print an existing Sales invoice through code. The example sends the report to screen. static void printSalesInvoiceThroughCode(Args _args)
{ SalesInvoiceJournalPrint salesInvoiceJournalPrint; Set set = new Set(Types::Record); SRSPrintDestinationSettings srsPrintDestinationSettings; // Add record set.add(CustInvoiceJour::findRecId(5637188088)); // Set printer settings srsPrintDestinationSettings = new SRSPrintDestinationSettings(); srsPrintDestinationSettings.fileFormat(SRSReportFileFormat::Screen); // Initalize salesInvoiceJournalPrint = SalesInvoiceJournalPrint::construct(); salesInvoiceJournalPrint.parmPrintFormletter(NoYes::Yes); salesInvoiceJournalPrint.parmUsePrintManagement(false); salesInvoiceJournalPrint.parmPrinterSettingsFormLetter(srsPrintDestinationSettings.pack()); salesInvoiceJournalPrint.printJournal(set); } |
|
|
|
|
|
|
With the help of the following lines, I want to show how you can post a sales packing slip by code.
Those, who want to have more control over the data to be posted, should take a look at the parameters of salesFormLetter.update().