Occasionally, people ask if it is possible to use Docentric Email Print Destination to send email to the customer without attaching the invoice.
Well, this is possible with a small code adjustment.
Since we distinguish two modes for email sending from D365FO, namely “Synchronous” and “Email processing”, there are two different approaches to achieve the desired result. More details about the email sending modes can be found at the link >> Report Email Sending Settings - Docentric AX
So, if you send emails in “Synchronous” mode, it means that the email will be sent directly from D365FO. In this case, you will need to intercept the creation of the email message in the Docentric pipeline and remove the email report attachment. You can do this by subscribing to the following delegate:
[SubscribesTo(classStr(DocReportRunDelegates), delegateStr(DocReportRunDelegates, beforeEmailMessageCreated))]
public static void DocReportRunDelegates_beforeEmailMessageCreated(DocPrintReportSettings _printReportSettings,
DocPrintDestSettingsEmail _emailPrintDestSettings,
DocPrintedReport _printedReport,
DocEventHandlerResult _result)
{
DocReportTable reportTable = DocReportTable::findActiveReport(_printReportSettings.parmReportId());
// If the report is printed to Docentric Email print destination in a Synchronous mode,
// then report content is removed before email is created.
if (_printReportSettings.parmReportId() == ssrsReportStr(SalesInvoice, Report) &&
reportTable.EmailEmailingMode == DocEmailSendingMode::Synchronous)
{
_emailPrintDestSettings.parmEmailAttachmentName('');
_printedReport.setReportContentContainer(conNull());
}
}
On the other hand, if you send an email in “Email processing” mode, it means that the email will not be sent directly from D365FO. Instead, it will be stored in the Batch email sending status queue and then sent by running the Email distributor batch. To see what enhancements Docentric has introduced for the Batch email sending status and the Email distributor batch, see the following link >> Improved Email Processing - Docentric AX
So, when emails are sent in “Email processing” mode, the email body and attachment are first stored in the Batch email sending status queue. This means that you need to delete the report attachment of the email after the email is saved in the queue.
To achieve this, you need to subscribe to the following delegate:
[SubscribesTo(classStr(DocReportRunDelegates), delegateStr(DocReportRunDelegates, afterSaveToOutgoingEmailTable))]
public static void DocReportRunDelegates_afterSaveToOutgoingEmailTable(SysOutgoingEmailTable _outgoingEmailTable,
DocPrintReportSettings _printReportSettings,
DocPrintDestSettingsEmail _emailPrintDestSettings,
DocPrintReportToEmailExecutionInfo _emailExecutionInfo,
DocPrintedReport _printedReport,
DocEventHandlerResult _result)
{
// If the report is printed to Docentric Email print destination in a EmailProcessing mode,
// then report content is removed after the email is saved to outgoing email table.
if (_printReportSettings.parmReportId() == ssrsReportStr(SalesInvoice, Report))
{
SysOutgoingEmailData outgoingEmailData;
delete_from outgoingEmailData where outgoingEmailData.EmailItemId == _outgoingEmailTable.EmailItemId;
}
}