UPDATE TO THIS ARTICLE
From Docentric version 3.4.3, saving reports to configurable Azure file shares is supported. You can mount an Azure file share as a network drive and this way enable routing from D365FO in the cloud to your local network.
Docentric introduces a new printing option Print as PDF that enables routing of PDF files from Dynamics 365 for Finance and Operations in the cloud to the local file system, for example a shared network folder.
Print as PDF is part of Docentric Free Edition, which you can download and use right away.
Print Customer invoice to a network folder
Let’s say that we want to post and print our invoices in D365FO in the cloud to the local file system, e.g. to a shared folder in our corporate network. For the same reason that we can't print D365FO documents on network printers, we can't save them to the local file system either.
By analyzing how D365FO prints checks via DRA running as a service, we noticed that there is a hidden property in the print settings, which triggers DRA to route PDF documents to a preconfigured local folder instead of printing them.
Learn more about how DRA works >>
In this article, we will explain how to print invoices to a shared network folder.
Set up the print settings for Customer invoice
In Print management setup, select Docentric Printer print destination and turn on the Print as PDF option. In PDF output filename we will use placeholders @COMPANYID@, @InvoiceAccount@ and @InvoiceId@, e.g. @COMPANYID@_@InvoiceAccount_@InvoiceId@.pdf to make it dynamic.
Run the Customer invoice report
Before we run the Customer invoice report, we will stop the DRA service, just to observe the Document routing status log. Next, we will run multiple invoices from Invoice journal. The invoices are generated and sent to the selected printer as PDF documents.
Note that the printer selection when printing reports using Print as PDF only affects which DRAs will handle them; those DRAs have the selected printer on their printer list.
We can also see that new records are created in the Document routing status table, containing the corresponding PDF output filenames in the Report name field, while Job status is set to Pending.
Now start the DRA service and see what will happen next. This is the expected result.
Troubleshooting if the document routing is not working
If no document is routed to the target folder nor printed to the target printer, you will notice that Job status is unchanged, i.e. it is still set to Pending in Document routing status. To learn more about the possible issues, check the logs within DRA.
There is more
Let’s demonstrate this on a simple example. Assume that we need to save all PDF documents from Attachments of a particular sales order to a shared network folder.
The following code will accomplish the task.
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 |
class DocRoutePdfAttachmentsToNetworkFolder { public static void main(Args _args) { SalesTable salesTable; select firstonly salesTable where salesTable.SalesId == '000002'; str targetPrinterName = 'HPDocentric (HP Officejet Pro 8610)'; DocuRefSearch docuRefSearch = DocuRefSearch::newCommon(salesTable); while (docuRefSearch.next()) { DocuRef docuRef = docuRefSearch.docuRef(); DocuValue docuValue = docuRef.docuValue(); if (docuValue.FileType != 'PDF') { continue; } using (System.IO.Stream docuRefStream = DocumentManagement::getAttachmentStream(docuRef)) { using (System.IO.MemoryStream attachmentMs = new System.IO.MemoryStream()) { docuRefStream.CopyTo(attachmentMs); DocPrinterManager::sendPdfDocumentToDocumentRouter( targetPrinterName, docuRef.filename(), attachmentMs.ToArray()); } } } } } |
After we configured DRA to point to the wanted local folder and ran it as a service, we can execute the above code and check the result.