Send Workflow Email Notifications with Attachments in D365FO

In our previous article, we explained how to configure and design email notifications for the Purchase requisition review workflow. Using Docentric improvements, you can design Email templates used for workflow notifications in the advanced email body editor with placeholders. But there is more – you can add any file you need to a workflow notification email as the email attachment.

In this article, we will demonstrate how to attach documents from the workflow entity, a purchase requisition header, to the workflow email notifications.

All Email templates improvements are part of Docentric Free Edition, so you can use it completely for free!

Setup

The setup is already described in the previous article; we need to configure the Purchase requisition review workflow to send email notifications based on WFEmail, a record from System email templates.

WFEmail in System email templates should be configured as described in the previous article but with one change though. We will use a different Class for placeholders, DocPurchReqWfEmailNotificationWithAttachmentsETH, to enable workflow email attachments.

 

The new class, DocPurchReqWfEmailNotificationWithAttachmentsETH, extends the previously used class, DocPurchReqWorkflowEmailNotificationETH, with an additional method:

Download the both classes >>

Note that the base class (DocEmailTemplateAdvancedHandlerWFAL) provides the access to the workflow entity, the PurchReqTable table record, so we can iterate through its Attachments (the related DocuRef records), and attach them to the outgoing email.

How to add attachments to outgoing emails

When a workflow email notification is created, it is stored in the Batch email sending status table (SysOutgoingEmailTable). On the other hand, its attachments are stored in the SysOutgoingEmailData table.

We extended the SysOutgoingEmailTable table with a few instance methods to enable adding the related attachments by inserting new records into the SysOutgoingEmailData table.

These additional methods insertAttachmentsFromCommon_DC(Common _commonTable), insertAttachmentFromDocuRef_DC(DocuRef _docuRef), and insertAttachment_DC(Filename _fileName, container _fileContent) are added to the SysOutgoingEmailTable table extension to the Docentric AX model in the 3.3.9 version.

Let’s create workflow email notifications with attachments

In order to test workflow email notifications with attachments, we will first create a new purchase requisition with two attachments and submit it to the Purchase requisition review workflow.

 

When the purchase requisition is approved, the workflow email notification is created and saved into Batch email sending status. We can view the outgoing email message, before it is sent by Email distributor batch, by clicking the Show message button. Note that the email message has two email attachments, the files from the corresponding purchase requisition header.

 

We also added a new button to the into Batch email sending status form, Download message, which will generate from the selected record the EML file that you can open in Outlook and check the email message attachments.

 

Resources

Download Class for placeholders for this example >>

See also

Send nicely designed emails from workflows >>
Learn in more detail how to create dynamic tables in Email templates >>
Enabling link to the WF entity in Email templates >>

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