Friday, March 24, 2023

Create table in email body using X++ code.



Hi All,
Today we are going to see how to create table in email body without using email templates. Please refer below example.

Note - Please make sure your email parameter setup is done and you able to send test email.

Expected result: 






















X++ Code
internal final class TestJobTableInEmailBody
{
    public static void main(Args _args)
    {
        SysMailerMessageBuilder messageBuilder = new SysMailerMessageBuilder();

        SysInfoLogStr   emailBodyWithHtml;
        EmailBase       fromEmail = 'no-reply-vendorportal@testgroup.com';
        EmailBase       toEmail = 'vijay.yelmame14@gmail.com';
        EmailBase       ccEmail;
        PurchTable      PurchTable;
        boolean emailSend;

        try
        {
            emailBodyWithHtml = "<table border = '1'><tr><td><b>Payment<b></td><td><b>Currency Code<b></td><td><b>DeliveryPostalAddress<b></td><td><b>Delivery Date<b></td></tr>";

            while select * from PurchTable where 
                PurchTable.OrderAccount =='TEst-VEN'
            {
                emailBodyWithHtml += "<tr><td>"+PurchTable.Payment+"</td><td>"+PurchTable.CurrencyCode+"</td><td>"+any2Str(PurchTable.DeliveryPostalAddress)+"</td><td>"+any2Str(PurchTable.DeliveryDate)+"</td></tr>";
            }
            emailBodyWithHtml += "</Table>";

            messageBuilder.setBody(strFmt(strRem(emailBodyWithHtml, '\r')),true);

            messageBuilder.setSubject("Test Email");
            messageBuilder.addTo(toEmail);
            //messageBuilder.addCc(ccEmail);
            messageBuilder.setFrom(fromEmail);

            emailSend = SysMailerFactory::sendNonInteractive(messageBuilder.getMessage());

        }
        catch
        {
            warning("@Res:NotificationEmailNotSent");
        }
    }

}




How to Post Partial Product Receipt in D365FO Using X++ Code

How to Post Partial Product Receipt in D365FO Using X++ Code How to Post Partial Product Receipt in D365FO Using X++...