Search This Blog

Tuesday 17 March 2020

Adding Subject and Body to the report send in an email by using the Print Management in D365 for Finance and Ops

As you already know there are standard AX Documents that you can print or send in an email using print management destination settings.

By using the below configuration in print management settings.



























But the problem is once you receive the document in an email that was sent through print management. It does not contain any user-friendly subject or body of the email.

Like this:










There was the requirement to include the Subject and Body to the email that is sent through print management.

For this what we did we created a parameter where we set up the email template and inside that email template, we specified the subject and email body.














below is the code snippet that we have used:

/// <summary>
/// Extension for class <c>PrintMgmtReportRun</c>
/// </summary>
[Extensionof(classstr(PrintMgmtReportRun))]
final class FBHPrintMgmtReportRun_Extension
{
    /// <summary>
    /// COC for SettingDetail method
    /// </summary>
    /// <returns></returns>
    public PrintMgmtPrintSettingDetail settingDetail()
    {
        PrintMgmtPrintSettingDetail     currentSettingDetail;
        currentSettingDetail = next settingDetail();

        if (this.parmDocType() == PrintMgmtDocumentType::VendPaymAdvice
            || this.parmDocType() == PrintMgmtDocumentType::CustPaymAdvice)
        {
            SRSPrintDestinationSettings printDestinationSettings;
            printDestinationSettings = currentSettingDetail.parmPrintJobSettings();

            if (printDestinationSettings.printMediumType() == SRSPrintMediumType::Email)
            {
                SysEmailId              sysEmailId;
                SysEmailTable           emailTable;
                SysEmailMessageTable    emailMessageTable;
                FBHVendParametersExt        vendParameters;
                FBHCustParametersExt        custParameters;

                if (this.parmDocType() == PrintMgmtDocumentType::VendPaymAdvice)
                {
                    select firstonly PaymAdviceEmailTemplateId from vendParameters;
                    sysEmailId        = vendParameters.PaymAdviceEmailTemplateId;
                }
                else
                {
                    select firstonly PaymAdviceEmailTemplateId from custParameters;
                    sysEmailId        = custParameters.PaymAdviceEmailTemplateId;
                }

                emailTable        = SysEmailTable::find(sysEmailId);
                emailMessageTable = SysEmailMessageTable::find(sysEmailId, emailTable.DefaultLanguage);

                printDestinationSettings.emailSubject(emailMessageTable.Subject);
                printDestinationSettings.fbhEmailBody(emailMessageTable.Mail);
            }
        }
       
        return currentSettingDetail;
    }


}

now after doing the above change when you try to receive the report in an email that was sent through print management then you will receive the like this which contains the subject and body as well that you have set up in email template.