Wednesday, June 26, 2019

How to customize customer/Sales order invoice email body and subject in Dynamics 365 F&O X++

In this post I'm going to show you how to send customer invoices with custom email subject and body .

For that I created below class to extend  SrsReportRunPrinter. I'm adding invoice ID in the subject and using HTML for body. Change the code according to your requirement.

[ExtensionOf(classStr(SrsReportRunPrinter))]
final class Class_SrsReportRunMailer_Extension
{
public void printReport()
    {
        SrsReportDataContract contract = reportContract;

        if(contract && SRSPrintMediumType::Email && contract.parmRdpContract() as salesInvoiceContract)
        {
            salesInvoiceContract salesInvoiceContract;
            CustInvoiceJour custInvoiceJour;
            ;

            salesInvoiceContract  = contract.parmRdpContract();
         
            str InvoiceId = CustInvoiceJour::findRecId(salesInvoiceContract.parmRecordId()).InvoiceId;
         
            SRSPrintDestinationSettings     printSettings = contract.parmPrintSettings();

            SrsReportEMailDataContract emailContract = printSettings.parmEMailContract();
         
            printSettings.fileName("Invoice #"+InvoiceId);
         
            str parmSubject = emailContract.parmSubject();

            emailContract.parmSubject(parmSubject +"  " +"#"+InvoiceId);

            str body;

            body = "<html><body>"+ strfmt("Dear Customer,")+ "<br/><br>"+
                strfmt("Please find your invoice attached.") + "<br/><br>"+
                strfmt("Regards,")+ "<br/>"+
                strfmt("Test Team")+ "<br/><br>";
         
            emailContract.parmBody(body);

            //contract.parmPrintSettings().emailSubject(body);
        }
     
        next printReport();

    }

}

That's it. You can contact me for any additional questions.

@Rahul

1 comment:

  1. Really helpful walkthrough! Customizing invoice emails in Dynamics 365 F&O with X++ makes customer communication so much more professional. The example code you shared is clean and easy to tweak. By the way, for anyone managing projects or business sites, having reliable lifetime web hosting can be just as important as streamlining ERP workflows.

    ReplyDelete

What is the primary purpose of using a Solution in Microsoft Power Platform & ALM?

As organizations embrace low-code development with Microsoft Power Platform , it becomes essential to manage and govern apps, flows, and dat...