Let’s say that we want to email reports from Dynamics 365 for Finance and Operations with some attractive content in the email body including images. Beside static content, some email parts can be dynamic and specific for every report execution. Standard Dynamics 365 for Finance and Operations supports sending emails with attached reports, but without the email body and consequently, without any dynamic content. Also, using the built-in functionality you can set up the email subject only as a static text and you cannot even affect the email attachment name.
With Docentric's Email print destination you can edit all email parts and enhance them with dynamic content. You can insert placeholders which will be replaced with content before sending. Text placeholders are replaced with text, while image placeholders are replaced with images, e.g. loaded from the database.
Learn on how to insert a company logo in the email body >>
With placeholders and rich HTML content you can easily create a dynamic, rich and appealing emails. This functionality is fully supported by Docentric AX Free Edition, which brings many improvements for other print destinations as well.
Some placeholders are supported out-of-the-box for all reports; they are called standard placeholders. There are also custom placeholders that are specific per report, provided by an additional model called Docentric AX SSRS Replicas for commonly used reports such as Customer invoice and Purchase order. This article demonstrates how to introduce and implement an additional custom image placeholder, and how to use it in the email body.
Let's say that our scenario requires sending Sales order confirmation by email, in which we want to use additional placeholders: SalesTakerName and SalesTakerImage. In order to introduce these placeholders, we will first need to add the corresponding attributes to the method DocSalesConfirmDSP.overrideReportRunSettings().
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
... #define.ConfirmDate('ConfirmDate') #define.ConfirmDocNum('ConfirmDocNum') #define.SalesTakerName('SalesTakerName') #define.SalesTakerImage('SalesTakerImage') [DocPlaceholderAttribute(#SalesId, 'SO - Sales ID'), DocPlaceholderAttribute(#CustAccount, 'SO - Customer Account ID'), DocPlaceholderAttribute(#CustName, 'SO - Customer Name'), DocPlaceholderAttribute(#CustContactName, 'SO - Customer Contact Name'), DocPlaceholderAttribute(#CustRef, 'SO - Customer Reference'), DocPlaceholderAttribute(#DeliveryName, 'SO - Delivery Name'), DocPlaceholderAttribute(#ConfirmDate, 'SO - Confirm Date'), DocPlaceholderAttribute(#ConfirmDocNum, 'SO - Confirm Document Number'), // added SalesTakerName and SalesTakerImage placeholders DocPlaceholderAttribute(#SalesTakerName, 'SO - Sales Taker Name'), DocPlaceholderImageAttribute(#SalesTakerImage, 'SO - Sales Taker Picture', 80, 80)] // defaultHeight=80, defaultWidth=80 public DocPlaceholderManager overrideReportRunSettings(DocReportRunContext _reportRunContext, boolean _replaceStandardPlaceholders = true) { DocPlaceholderManager placeholderMng = super(_reportRunContext, _replaceStandardPlaceholders); // -- Placeholder @SalesId@ placeholderMng.replacePlaceholderInCurrentPrintDest(#SalesId, salesTable.SalesId); ... |
Please note that we've added SalesTakerName as a text custom placeholder using the DocPlaceholderAttribute attribute, while SalesTakerImage has been added as an image custom placeholder using the DocPlaceholderImageAttribute attribute.
Then, in the same method, we need to add the code that fills the values of these attributes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
if (_reportRunContext.parmPrintDestination() == DocPrintDestination::Email) { ... // -- Placeholder @SalesTakerName@ placeholderMng.replacePlaceholderInCurrentPrintDest(#SalesTakerName, HcmWorker::find(this.custConfirmJour().WorkerSalesTaker).name()); // -- Placeholder @SalesTakerImage@ if (DocPlaceholderManager::findPlaceholder(_reportRunContext.emailPrintDestSettings().parmEmailBody(), #SalesTakerImage)) { HcmWorker worker = HcmWorker::find(this.custConfirmJour().WorkerSalesTaker); if (worker) { Bitmap workerImage = worker.personImage(); if (workerImage) placeholderMng.replacePlaceholderImage(#SalesTakerImage, workerImage); } } ... } |
After the code is compiled, open Print management setup > Sales order confirmation and choose Docentric Email print destination. Enter the email body content and insert the Sales Taker Name and Sales Taker Image from the Fields drop down list. Text placeholders are inserted as @Placeholder@, while image placeholders are inserted as blank pictures.
In Source view you can see the <img> HTML tag and its attributes. Height/width define the image size in received emails. Default values are defined through DocPlaceholderImageAttribute, but you can change or remove them. If height/width are not defined, an email client will show the picture with the dimensions inferred from the image content.
When you insert an image placeholder this is what you get:
1 |
<img style="height: 80px; width: 80px;" src="cid:@SalesTakerImage@" width="80" height="80" /> |
You can omit the width dimension, which means that the width of the real image will be applied in the email body.
1 |
<img style="height: 80px;" src="cid:@SalesTakerImage@" height="80" /> |
If you omit both height/width, the dimensions of the real image will be applied in the email body.
1 |
<img src="cid:@SalesTakerImage@" /> |
Let's say that we want to send Sales order confirmation to the customer's primary contact email. In order to do that we need to set the To field to the @@ email token.
If we print Sales order confirmation using Use print management, the email with the attached report will be send to the customer's primary email address.
The sent email looks like this one below.
See also
Learn how to use a company logo in the email body >>
Download and use Sales Order Confirmation with image placeholders >>
Watch Video on How To Configure and Use Report Email Templates (from 3.3.9 ver) >>