Email reports with customized body and additional attachments

Let’s say that we want to email purchase orders with customized body and two additional attachments, which are arbitrary documents stored on file system, SharePoint or database. Instead of attaching documents with static content, we can also attach related reports, for example Purchase order product receipt (the procedure is similar).

Navigate to Company/Accounts payable/Setup/Forms and open the Print management setup form. Locate the Purchase order report and open the Print destination settings form.

Turn on the Vendor primary contact option and also select the PO vendor purpose:

 

When we execute a purchase order to the Email print destination (e.g. by clicking the Use print management button on the Purchase order confirmations form), the email will be sent to the vendor primary contact, if defined, and to all vendor contacts with the PO contact information purpose assigned.
Read more about emailing purchase order to specific vendor contacts >>

Let's say that we want to customize the email subject, body and the attachment name. In order to do that, we can use both standard and custom placeholders:

The main difference between them is that you can introduce as many as needed custom placeholders with custom names, but you have to create business logic to handle them. This X++ code should be placed in the custom Docentric DSP class for the Purchase order report, specifically in the overrideReportRunSettings() method:

In the above method you can see that:

(1) For the Email print destination we replaced custom placeholders such as @VendContactName@, @PurchId@ and @ResponseEndDate@ with the corresponding values.

From ver. 3.3.4 we have UI for this functionality, see Report Attachments How-To Manual

(2) We also attached two additional attachments with fixed names located on a shared disk, but we could also make this more flexible by building a special setup for the Purchase order report.
Additional attachment can be added as a file located on file system or as a file content (container, i.e. binary) kept in the database or on SharePoint.

(3) For the File print destination we replaced some other custom placeholders such as @VendAccount@ and @PurchId@.

(4) We also chose different template depending on the calling report menu item (Preview Original or Copy).
Learn more about using more than one template per report >>

However, if some other report(s) should be attached next to the Purchase order report in the same mail (instead of these two static documents), we can use Docentric AX APIs to generate report from the code first, and then attach it in the same way.

Next, on the picture below you can see that on the Print destination settings form there is an option to open the email before sending. This is convenient for end users because enables them to append additional attachments from their computers, or to add some additional text, their signature, etc.
Note that the Open email before sending option is working only with MS Outlook desktop application, and when report doesn’t run in batch.

The final Print management setup looks like the following:

Of course, you have to be sure that the Docentric Purchase order report has the proper DSP class assigned (we called it for this example PurchPurchaseOrderDSP_OverrideRRS), with the overridden the overrideReportRunSettings() method, in the Docentric Reports setup form:

Resources

Class_PurchPurchaseOrderDSP_OverrideRRS.xpo

 

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