This post is machine-translated. The original post in german language can be found here.
These post applies to following version:
Dynamics AX 2012
Dynamics AX 2012
Nice post. How do I allow users to print sales invoice once. if another copy of the invoice is needed then someone with authority will allow it. |
@Lionel. Use access right on the re-print button(s) in invoice journal. Kind regards, Thomas. |
|
|
|
|
|
|
The following job demonstrates, how you can print an existing Sales invoice through code. The example sends the report to screen.
{
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());
// Print
salesInvoiceJournalPrint.printJournal(set);
}
Changing the parameter of the instance of SRSPrintDestinationSettings allows you to send the invoice to printer, file or mail. The next example creates a PDF-file.
{
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::PDF);
srsPrintDestinationSettings.fileName(@'c:\temp\invoice.pdf');
srsPrintDestinationSettings.printMediumType(SRSPrintMediumType::File);
srsPrintDestinationSettings.numberOfCopies(1);
srsPrintDestinationSettings.overwriteFile(true);
// Initalize
salesInvoiceJournalPrint = SalesInvoiceJournalPrint::construct();
salesInvoiceJournalPrint.parmPrintFormletter(NoYes::Yes);
salesInvoiceJournalPrint.parmUsePrintManagement(false);
salesInvoiceJournalPrint.parmPrinterSettingsFormLetter(srsPrintDestinationSettings.pack());
// Print
salesInvoiceJournalPrint.printJournal(set);
}
If you want to print multiple sales invoices at once, you have to add the corresponding CustInvoiceJour-records to the set called "set:
// Add record
set.add(CustInvoiceJour::findRecId(5637155842));
set.add(CustInvoiceJour::findRecId(5637145354));
...
To save the sales invoice additionally to print archive, you can add the following line:
srsPrintDestinationSettings.parmPrintToArchive(true);
...