You can print an existing Sales invoice to a PDF file named as SalesInvoice_<InvoiceId>.pdf through the following code, regardless of 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 53 54 55 56 57 58 59 |
public static void printSalesInvoiceToPdfFile() { SalesInvoiceController salesInvoiceController; SalesInvoiceContract salesInvoiceContract; CustInvoiceJour custInvoiceJour; SalesInvoiceJournalPrint salesInvoiceJournalPrint; SRSPrintDestinationSettings srsPrintDestSettings; DocPrintDestSettingsFile filePrintDestSettings; 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); salesInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo()); // Create print destination settings. srsPrintDestSettings = new SRSPrintDestinationSettings(); // Set the selected print destination to Docentric File print destination. srsPrintDestSettings.printMediumType(SRSPrintMediumType::File_DC); filePrintDestSettings = new DocPrintDestSettingsFile(); srsPrintDestSettings.parmFilePrintDestSettings_DC(filePrintDestSettings); // Set the Docentric File print destination settings. // -- Name of the output file. filePrintDestSettings.parmOutputFilename(@'\\Shared\SalesInvoice_@FIELD_InvoiceId@.pdf'); // -- Output file format. filePrintDestSettings.parmOutputFileFormat(DocOutputFileFormat::PDF); // 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(); } |
Hi,
For Email, we have mentioned PrintMediumType as Email_DC.
How to get all defaults value from PrintManagement (Docentric) setup for Email setting?
emailPrintDestSettings should get it from Print management. Here system is allowing only when giving all details.
.
VendInvoiceDocumentController vendInvoiceController;
VendInvoiceDocumentContract vendInvoiceContract;
VendInvoiceJour vendInvoiceJour;
SRSPrintDestinationSettings srsPrintDestSettings;
DocPrintDestSettingsEmail emailPrintDestSettings;
vendInvoiceController = new VendInvoiceDocumentController();
vendInvoiceController.parmArgs(args);
vendInvoiceController.parmShowDialog(false);
vendInvoiceController.parmLoadFromSysLastValue(false);
vendInvoiceController.parmReportName(
PrintMgmtDocType::construct(PrintMgmtDocumentType::PurchaseOrderInvoice).getDefaultReportFormat());
vendInvoiceContract = vendInvoiceController.parmReportContract().parmRdpContract();
vendInvoiceContract.parmRecordId(invoiceJour.RecId);
vendInvoiceContract.parmDocumentTitle(“@SYS99734″);
vendInvoiceContract.parmPrintCopyOriginal(PrintCopyOriginal::OriginalPrint);
vendInvoiceController.parmReportContract().parmRdpContract(vendInvoiceContract);
srsPrintDestSettings = new SRSPrintDestinationSettings();
srsPrintDestSettings.printMediumType(SRSPrintMediumType::Email_DC);
srsPrintDestSettings.fileFormat(SRSReportFileFormat::PDF);
srsPrintDestSettings.overwriteFile(true);
str filename = strfmt(‘CN-%1.pdf’,invoiceJour.InvoiceId);
srsPrintDestSettings.fileName(filename);
emailPrintDestSettings =new DocPrintDestSettingsEmail ();
emailPrintDestSettings.parmEmailAttachmentName(filename);
emailPrintDestSettings.parmEmailAttachmentFileFormat(DocOutputFileFormat::PDF);
emailPrintDestSettings.parmEmailFrom(‘from address’);
emailPrintDestSettings.parmEmailTo(‘to address’);
emailPrintDestSettings.parmEmailSubject(‘Auto docentric email subject’);
emailPrintDestSettings.parmEmailBody(”);
srsPrintDestSettings.parmEmailPrintDestSettings_DC(emailPrintDestSettings);
vendInvoiceController.parmReportContract().parmPrintSettings(srsPrintDestSettings);
vendInvoiceController.startOperation();
Thanks,
For a precise answer we would need to know your specific use case.
If you just want to send VendInvoiceJour report from code using the Print management setting, the easiest way is to invoke output menu item PurchInvoice with selected VendInvoiceJour record.
If you want to load the current (default) Print management settings and change them later use the code below.
DocPrintMgmtSettingsEntity printMgmtSettingsEntity;
select firstOnly printMgmtSettingsEntity where
printMgmtSettingsEntity.DocInstanceDocumentType == PrintMgmtDocumentType::PurchaseOrderInvoice &&
printMgmtSettingsEntity.DataArea == curExt();
SRSPrintDestinationSettings srsPrintDestSettings = new SRSPrintDestinationSettings();
srsPrintDestSettings.unpack(printMgmtSettingsEntity.PrintJobSettings);
If you need further help on your specific case, please contact support@docentric.com.
Hello,
I follow the example of code but i did not found the method parmGeneratedDocFilename of class filePrintDestSettings. So I have error. I tried with filePrintDestSettings.parmFileSystemFilePath(@”C:\Temp\PurchPurchaseOrder.pdf”); but the report is not saved automatically in the path. The code is ignored. The pdf is to be downloaded in path that i should select manually.
Could you help me please ?
Thank you in advance
Hi,
If you have D365FO, this code is not applicable; namely, it’s written for AX 2012. Anyhow, in D365FO cloud environments you cannot save files to local file system; instead, you can use document routing as described here.
On the other hand, for D365FO on-premises environments there is no such limitation and you can use the similar approach as here; just set up the ‘Save to File system’ option to true and the target folder path to your destination network folder, e.g. \\server\folder.
Hope that this helped!
Kind regards,
Ana