Print Reports to Attachments in D365FO

Print Reports to Attachments in D365FO

You can print particular reports such as invoices and collection letters to Attachments of the corresponding journals only by using the e-Invoice attachment option settable on the customer card in Dynamics 365 for Finance and Operations. But what if you want to save an invoice to Attachments of the customer or sales order instead? Or if you need to reprint the invoice and replace the existing document for some reason? What if you simply want to change Document type used for e-Invoice Attachment, which always set to File?

All of this you can achieve with Docentric Free Edition, a completely free D365FO app, which you can download here.

In this article, we will explain how to print Sales invoice to Attachments of the corresponding sales order. The prerequisite is that you also have Docentric SSRS Replicas installed.

Setup for printing to Attachments

It’s very easy – just open the Print destination settings form from Print management setup for Customer invoice, and select Docentric File print destination. Then turn on the Save to Attachments option and set additional parameters Document type, target Record type and whether the attachment file content should be replaced if the attachment with the same filename already exists – see the If Attachment already exists combobox.


Record type

We selected Source table, because we want invoices to be saved to Attachments of sales orders, and in case of Sales invoice, the source table is Sales order (SalesTable). Similarly, for the Purchase order report the source table is Purchase order (PurchTable). If we selected Account table or Journal as Record type, the invoice would be saved to Attachments of the customer or the journal record respectively.

Context record refers to the record that the printing of the report is invoked from. For example, in case of Work report this is the underlaying Work record. In case of Sales invoice, Context record is always the corresponding SalesTable table.


You can also set the Restriction property of the resulting attachment to Internal/External. This affects e-Invoices because only external attachments can be embedded in e-Invoices.


The result

If we print an invoice using Docentric File print destination with the previous setup, the output document will appear in Attachments of the related sales order. Note that the output filename of the attached document is Rechnung CIV-0001.pdf, which we achieved by using label @SYS14204 (translated as Invoice in English) and placeholder @InvoiceId@.



There is more

We extended Attachments with the new fields: Category, Language, Tags, Active from and Active to. These settings are useful when emailing reports with additional email attachments. Learn more >>


If you print a report to Attachments using Docentric File print destination with a particular Category or Language, you will be able to use these values to select the printed report as the additional email attachment of another or even the same report (e.g. by using Print management).

Moreover, in one of the next product releases, you will be able not only to select additional email attachments but also to set up which attachments you want to embed or merge to the output documents. How awesome is that!

2 thoughts on “Print Reports to Attachments in D365FO

  1. I would like to transmit a project invoice PDF with merged attachments plus one or more additional PDF’s as separate attachments.  Presuming I’ve tagged those PDF’s to be merged into the invoice PDF while the others are not tagged, can this be done?

    1. Hi Patrick,

      Thank you for the interesting question!

      This should be possible via customization. We have an article explaining how to merge the purchase order report with attachments that are found on the items on the purchase order.

      The article can be found here.

      In your case instead of asking if the files are of type pdf, you can use our helper class DocGlobalHelper and the containsTags() method to check whether the pdf files are tagged and add them to the attachmentsList for merging with the report.

      You can get the tags from the Tags_DC field on the DocuRef table.

      For the attachments that are not tagged, you will need to add those to a container which has other containers inside of it in the form of [attachmentName, attachmentContent].

      The attachment name must end with a file extension, like the ones stored in the originalFileName field on the DocuValue table.
      The attachment content can be fetched via the DocumentManagement::getAttachmentStream() method.

      You can then add this container to the email additional attachments in the try catch block, just by calling the emailPrintDestSettings.parmEmailAdditionalAttachments() method.

      You can get the emailPrintDestSettings from the print report settings, like so:
      DocPrintDestSettingsEmail emailPrintDestSettings = _printReportSettings.parmSrsReportContract()

Leave a Reply

Your email address will not be published. Required fields are marked *


Docentric respects your privacy. Learn how your comment data is processed >>

Docentric respects your privacy. Learn how your comment data is processed >>