28 Mar’19

D365 Business CentralHow to attach a table structure in a mail in Business Central

Introduction:

In this blog, I want to depict how a table structure can be integrated into an Email in Business Central using the HTML tags.

Pre-Requisites :

  1. Microsoft Dynamics 365 Business Central
  2. HTML

Steps:

  1. Create an Email Structure using the SMTP Mail setup Codeunit and pages. The body that is to be attached to the Mail will be the table structure that will be created using HTML tags.
  2. The HTML tags used are as follows:

<th> : To create the heading for the table

<tr>: To create the rows for the table

<td>: To input the data for the table

Code for the table structure and mail is as follows:

SMTPSetup.CreateMessage('', SMTPMailSetup."User ID", Rec_Contact2."E-Mail", 'Scheduling Report', '', TRUE);
SMTPSetup.AppendBody(MailBody);
SMTPSetup.AppendBody('<br>');
SMTPSetup.AppendBody(UserDetails);
SMTPSetup.AppendBody('<br>');
SMTPSetup.AppendBody('<table border="1">');
SMTPSetup.AppendBody('<tr>');
SMTPSetup.AppendBody('<th>Purchase Conformation</th>');
SMTPSetup.AppendBody('<th>Vendor Name</th>');
SMTPSetup.AppendBody('<th>Vendor Ref:</th>');
SMTPSetup.AppendBody('<th>Product Name</th>');
SMTPSetup.AppendBody('<th>Estimated PU Date</th>');
SMTPSetup.AppendBody('<th>PU Date</th>');
SMTPSetup.AppendBody('<th>PU Time Begin</th>');
SMTPSetup.AppendBody('<th>PU Time End</th>');
SMTPSetup.AppendBody('</tr>');
SMTPSetup.AppendBody('<tr>');
SMTPSetup.AppendBody('<td>' + Format("Blanket PO No.") + '-' + Format("Blanket PO Line No.") + '</td>');
SMTPSetup.AppendBody('<td>' + Format(Name) + '</td>');
SMTPSetup.AppendBody('<td>' + Format(VSO) + '</td>');
SMTPSetup.AppendBody('<td>' + Format(ProductName) + '</td>');
SMTPSetup.AppendBody('<td>' + Format(EstPUDate) + '</td>');
SMTPSetup.AppendBody('<td>' + Format(PUDate) + '</td>');
SMTPSetup.AppendBody('<td>' + Format(PUStartTime) + '</td>');
SMTPSetup.AppendBody('<td>' + Format(PUEndTime) + '</td>');
SMTPSetup.AppendBody('</tr>');
SMTPSetup.AddCC(Rec_UserSetup."E-Mail");
SMTPSetup.Send;

3) The table output looks as follows when the mail is sent:

 

 

 

 

 

 

 

Conclusion:

Thus, using the basic HTML table tags a table structure can be integrated into the Email functionality of Business Central.

Written by

Dhruv Mehta

Trainee Software Engineer

Leave a Reply

Your email address will not be published. Required fields are marked *

Want to streamline your business processes?

  • This field is for validation purposes and should be left unchanged.

Recent Articles

  • Expenses in PSA for Fixed Bid and T&M contracts

    23 August’ 2019

    Problem Definition: One of my clients decided to use Expense module in PSA and to his surprise he could see the amount v...

    Read more
  • Setup Dockers

    23 August’ 2019

    Docker is an independent container platform that enables organizations to seamlessly build, share and run any applicatio...

    Read more
  • Qualify Lead in D365 CE: Select which entity records should be created

    20 August’ 2019

    Wave 2019 Updates brought some really sought-after features. Another one which I would like to bring up is the Lead Qual...

    Read more
  • Early Opt-in for October 2019 Wave 2 Updates

    20 August’ 2019

    August 2, 2019 was when the Wave 2 Updates were to be out. And here we are! By now, you should have gotten the option to...

    Read more
  • Setting Unified Interface App Icons

    20 August’ 2019

    Default App Icons for typical D365 environment look like these.But here’s what you can do to change these to put...

    Read more
  • We respect your privacy.
  • This field is for validation purposes and should be left unchanged.