Wednesday, June 22, 2022

How to add sender email address for Payment remittance (Advice) in D365FO

How to Add Sender Email Address for Payment Remittance (Advice) in D365FO

How to Add Sender Email Address for Payment Remittance (Advice) in D365FO

Hi All,

Thank you for visiting this blog. This blog is all about how to set the from email address for Print Management functionality.

As we all know, there is no option in standard to configure the sender email address for the Payment advice report or any other report which is printing through Print Management, except if we configure it by electronic reporting. So let's see how we can achieve this by doing a very small customization.

Please visit my previous blog for how to set email subject from print management.

If you look into the standard class SrsReportRunMailer, there is a method buildFromEmailAddress(). This method is picking the email address of the current user ID and using it as the from email address. This we want to change to the custom parameter, i.e., Test@gmail.com.

PS - I am writing COC of emailReport() method of class SrsReportRunMailer because buildFromEmailAddress() method is declared as private so we cannot create COC or event handler of it.

Please follow the below steps to complete this customization.

Step 1: Create a New Parameter

Create a new parameter in the accounts payable parameter form to store the from email address.

Step 2: Create a New Class

Create a new class to write COC of emailReport() method. The class name should end with _Extension. Example: TestSrsReportRunBuilder_Extension


[ExtensionOf(classStr(SrsReportRunMailer))]
public final class TestSrsReportRunBuilder_Extension
{

}
    

Step 3: Add the Below Code


public boolean emailReport(SrsReportEMailDataContract emailContract, System.Byte[] reportBytes, str fileName)
{
    str tofindStr = 'Payment advice'; // this string should be present in email subject which can be defined in Print Management parameter.
    str emailSubject = emailContract.parmSubject();

    if (strScan(emailSubject, tofindStr, 1, strLen(emailSubject))) 
    {
        fromAddress = VendParameters::find().TestFromEmailAddressPaymentAdvice;
        mailer = this.parmSysMailer();
        if (!fromAddress || !SysEmailDistributor::validateEmail(fromAddress))
        {
            error(strfmt("@SYS134596", "@SYS4083"));
        }
    }

    // Next call
    boolean ret = next emailReport(emailContract, reportBytes, fileName);
    return ret;
}
    

Expected result :

Example Image

4 comments:

  1. Is there any way to include email body from email template under Organization Administration ?

    ReplyDelete
  2. Hi Amit,
    By code I don't see there is any way we can pick email templates from organization and administration but you can check the post shared by Ian in comments box over LinkedIn,Also if you want to achive this by custom code then check my another blog.Link provided in code section of this blog.

    ReplyDelete
  3. Hi Vijay, where we can see the email body of the payment advice report, like in your email screen shot, or where we can find the email body for payment advice report.

    ReplyDelete
  4. Hi Akbar,
    This email body is coming from custom field,

    Please check this blog.
    https://d365fotechnicalblog.blogspot.com/2022/05/modify-email-subject-and-body-of-print.html

    ReplyDelete

How to show default value or first value for the field which is not part of group and returning more than one values

Grouping Data by Certain Fields and Handling Cases Where a Specific Field Returns More Than One Value in D365FO SSRS Report...