Using Email tokens with SSRS Email print destination

When setting up the Print Management settings for reports in Accounts Receivable and Accounts Payable module in Dynamics 365 for Finance and Operations, you can specify in the To and Cc email addresses fields so called email tokens. For example, you can use the Primary contact and Contact purpose email tokens for a customer (Accounts Receivable) or a vendor (Accounts Payable) when emailing, e.g. an invoice or a purchase order.

Let’s say that you want to email each invoice to all those customer’s contacts which are marked with a special Contact purpose: Invoice. You will then simply select Invoice as Purpose on the Print destination settings form in the Print Management setup, as it is shown on the picture below. So, each time when an invoice is emailed using Print management, the emails with the attached invoice document will be sent to all the corresponding customer’s contacts with the Invoice purpose. Similarly, you can also use the Primary contact email token, in which case invoices will be sent to the customer’s primary contact email.

What if a customer has no primary contact nor any contact of type Email address that the Invoice purpose is assigned to? As you can see on the pictures below, resolving of these two email tokens results in warnings, and no email will be sent.

This built-in behavior can be changed if you are using Docentric AX Free Edition.

Let’s say that we want to do it in the following way: if for a printing invoice and the corresponding customer no email contact with Invoice purpose cannot be found (or primary contact email), instead of stopping the report execution we will send the problematic invoice to a specific internal email account (e.g. info@docentric.com). We will also change the email subject to describe the problem so that we know when such an email is received to take the appropriate action (e.g. to resend the email to the valid customer email addresses). We can still have the warnings about missing customer contact information, or we can easily remove them or transform them into some kind of logging.

In order to achieve this, we will introduce a new Docentric DSP class, DocSalesInvoiceWithCustomPurposePlaceholderDSP, which will handle these special requirements in its overrideReportRunSettings() method.

Learn in detail on how to define custom placeholders with Docentric >>

First, we are going to define two new placeholders (@InvoicePurpose@ and @PrimaryEmail@) which will be used instead of the built-in ones (@Invoice@ and @Primary@). This way we are going to avoid the built-in warnings. These two email tokens are defined as the attributes on the overrideReportRunSettings() method. Next, we will implement the above described logic in the same method in the following way.

After that, to apply the new functionality we need to assign the new DocSalesInvoiceWithCustomPurposePlaceholderDSP DSP class to the Sales invoice report in Docentric report setup, as it shown on the picture below.

Afterwards, we also need to change the Print Management setup for the Sales invoice report to use these two new placeholders: @InvoicePurpose@ and @PrimaryEmail@ instead of the built-in @Invoice@ and @@.

When we now email an invoice by using Print Management we will get the different warnings (that could also be easily removed).

 

We will also get an error email in our internal inbox.

In fact, you can adjust these emailing rules as you please. You can even cancel sending such an email (without the valid To email addresses field) by subscribing to the DocReportRunDelegates.printToEmailBegin delegate or some other delegates defined in the report execution pipeline.

Additionally, with Docentric AX Free Edition you can define and edit HTML body, subject and attachment name with custom placeholders, send an email with multiple attachments and also use Bcc email addresses. Learn more >>

Resolving customer contact purpose

Resolving customer primary email

custTable.email()

Similarly, when printing a report from Accounts Payable module, e.g. Purchase order you can use the custom @PO@ (Purchase order purpose) and @PrimaryEmail@ tokens.

Resolving vendor contact purpose

Resolving vendor primary email

vendTable.email()

Resources

Download the DSP class

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