28 Mar’19

D365 Business Central

How 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

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

  • How to enable Document ID in SharePoint Online

    16 May’ 2019

    Introduction: As you know that SharePoint Online can be used as a document management platform and with the help of Docu...

    Read more
  • Count Number of files in SharePoint folder

    15 May’ 2019

    Introduction: This blog explains how to Count No of files in SharePoint folder using MS Flow. Steps to be followed:Sel...

    Read more
  • Professional Services Automation (PSA) for CPA firms

    14 May’ 2019

    With the evolution of Technology, every industry is getting process oriented and so are CPA firms getting more organized...

    Read more
  • What if the Resource Requirement Still appears post the task is deleted from Schedule (WBS) in PSA V3?

    13 May’ 2019

    Problem Definition: I have observed a fact in PSA that when the task in PSA Schedule (WBS) is deleted, the corresponding...

    Read more
  • Discount Settings for D365 Sales Line Items – Line Items or Per Unit?

    10 May’ 2019

    For Line Item entities Opportunity Products, Quotes Products, Order Products or Invoice Products, you can chose what typ...

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