Send Sales and Project invoice in the single email in D365FO

In the previous article, we explained a utility class that helps you generate SSRS and Docentric reports from X++ in memory instead of distributing them to a print destination such as Email or File. Using the same helper class, DocSrsReportGenerator, we will now demonstrate how to send Sales and Project invoice in the single email to the corresponding customer.

We will cover two scenarios:

  • Send Sales and Project invoice as separate attachments in the same email.
  • Merge Sales and Project invoice and email them as the single attachment.
Note that the DocSrsReportGenerator class is part of Docentric Free Edition as well as the code that follows, so you can use the solution from this article completely for free.

Extend DSP class for Sales invoice

Assume that we want to email both Sales and Project invoices when printing a Sales invoice. This means that we need to customize the Sales invoice printing pipeline, and we will do that by extending Docentric DSP class for Sales invoice.

Learn more about Docentric DSP classes >>

Once we build the project/model containing the DocSalesInvoiceWithPSAProjInvoiceReportDSP class, it will become available in Docentric report setup, where we have to select it as DSP class for the Sales invoice report.

 

Merge Sales and Project invoice

If you don’t want to merge Sales and Project invoice, you’re done! However, in order to merge them, you will need to have the following event handler implemented as well.

The above method handles the event published each time a report content is generated, so we first have to check if this is the SalesInvoice report. Next, we will merge the generated report (SalesInvoice) with the one we generated in the DocSalesInvoiceWithPSAProjInvoiceReportDSP class (PSAProjInvoice).

Alternatively, if we didn’t need to send PSAProjInvoice as the additional email attachment, we wouldn’t need the custom DSP class at all, but this event handler would suffice. In this case, it should also contain logic for generating the related Project invoice before merging it with Sales invoice.

In general, the DocReportRunDelegates.generateReportContent event handler enables merging of output documents for any report with other PDF documents, for example T&Cs or specifications, which can be stored in Attachments of the related journal, account or source table records.

The result

When we run Sales invoice from Invoice journal, the result is the following.

 

 

As we can see, Docentric Free Edition offers flexible code injection points, which we can use to achieve various custom scenarios such as generating another report and adding it as the additional email attachment, or merging it with the main report document before emailing, saving to SharePoint or embedding into e-Invoice.

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 >>