Dynamics 365 Business Central: Adding a Factbox to display the sent email (Link between mails and source entities)

Dynamics 365 Business Central

Hi, Readers.
As you might know, Enhanced email capabilities have been released in Business Central 17.1.
With this feature, administrators can make that easier to do by connecting one or more email accounts to Business Central.

So you can send documents without having to open an email app.
For example: Send by Email on Posted Sales Invoices page

After you send the email, you can find the history emails in the Sent Emails page.

For more details about new email features:
Enhanced email capabilities and Field Monitoring Setup
Set Up Email

But with the standard features, we cannot link between mails and source entities directly. So in this post, I would like to share an easy way, adding a Factbox to display the sent email.

First, let’s look at the table of the Sent Emails page.

table 8889 “Sent Email”: Although the Access property of this table is Public, many fields are Internal, so these fields cannot be extended and displayed on your own customized page.

‘Description’ is inaccessible due to its protection level

So, how to do it.
For example, add a new factbox to display sent email on the Posted Sales Invoice page.

1. Create a new ListPart page.

Source Code:

page 60110 "Sent Emails for Document"
{
    Caption = 'Sent Emails for Document';
    PageType = ListPart;
    ApplicationArea = All;
    UsageCategory = Lists;
    SourceTable = "Sent Email";
    SourceTableTemporary = true;
    InsertAllowed = false;
    Editable = false;
    DeleteAllowed = false;
    CardPageId = "Email Viewer";

    layout
    {
        area(Content)
        {
            field("Mail Id"; 'Sent: ' + Format(Rec.SystemModifiedAt))
            {
                Caption = 'Mail';
                ApplicationArea = All;
            }
        }
    }

    procedure AddBuffer(var SentEmailTemp: Record "Sent Email" temporary)
    begin
        Rec.Reset();
        Rec.DeleteAll();
        Rec.Copy(SentEmailTemp, true);
        CurrPage.Update();
    end;
}

2. Create a PageExtension

Source Code:

pageextension 60110 "Posted Sales Invoice Email Ext" extends "Posted Sales Invoice"
{
    layout
    {
        addfirst(factboxes)
        {
            part(SentEmails; "Sent Emails for Document")
            {
                ApplicationArea = All;
            }
        }
    }
    trigger OnAfterGetCurrRecord()
    var
        SentEmailTemp: Record "Sent Email" temporary;
        Email: Codeunit Email;
    begin
        SentEmailTemp := Email.GetSentEmailsForRecord(Database::"Sales Invoice Header", Rec.SystemId);
        CurrPage.SentEmails.Page.AddBuffer(SentEmailTemp);
    end;
}

The key point: Email.GetSentEmailsForRecord(Database::”Sales Invoice Header”, Rec.SystemId);

Completed.

Test Video:

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL