Wednesday 26 June 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

No comments:

Post a Comment

Adding a newline into a string in C# and X++

Below is the sample code we can use for  adding a newline after every occurrence of "@" symbol in the string in C#   using System...