Hi, Readers.
Today I would like to briefly talk about a qustion I saw in the Dynamics 365 Community before, how to display “Sent To” on the Sent Emails (8883, List) page? More details: How or what form to be used to fetch Sent to details in Sent Email Page in Business Central
The Sent Email page in Business Central does not display the ‘Sent To’ details. It only shows fields like Email Subject, Sent From, and Sender. Is there any standard report in Business Central to retrieve this information, or would it require a custom approach?
How or what form to be used to fetch Sent to details in Sent Email Page in Business Central
You can easily share information and documents, such as sales and purchase orders and invoices, by email directly from Business Central, without having to open an email app. For example,


Sent emails can be accessed and reviewed via the ‘Sent Emails’ page in Business Central.

However, there’s a small problem here: this page shows “Sent From” but not “Sent to”.

You can find Send to if you click on Description or choose Edit and Send.


So, can we add this field?
First, the source table of this page is temporary.

Furthermore, table 8889 “Sent Email” does not have a “Sent To” field.

And, in this table, except for the Id field, all other fields have their Access attribute set to Internal.

So how does the standard obtain this Sent To? Let’s take a look at the following page.
page 12 “Email Viewer”:

It was obtained using the following method.

However, the Access property of codeunit 8905 “Email Message Impl.” is also set to Internal.

So, is there no solution? Actually, there is. Let’s dive into the details.
First, we can find the following two methods in codeunit 8904 “Email Message”.

procedure Get(MessageId: Guid): Gets the email message with the given ID.

procedure GetRecipients(……): Gets the recipents of a certain type of the email message.

We can use this codeunit to replace codeunit 8905 “Email Message Impl.”. The next question is, how do I retrieve the “Message Id” when the Access property is set to Internal?

We’ve discussed this before. More details: Dynamics 365 Business Central: Can we access the standard internal table/field (Access Property = Internal) via AL???

Now that we have all the pieces in place, let’s take a look at the final result.

Done.

Great. Give it a try!!!😁
Source code: Github (Please note that the source code is for reference only, you can improve it according to your own needs)
pageextension 50105 SentEmailsExt extends "Sent Emails"
{
layout
{
addafter(Sender)
{
field(ToRecipient; ToRecipient)
{
ApplicationArea = All;
Caption = 'Sent To';
ToolTip = 'Specifies the recipients of the email.';
Editable = false;
}
}
}
var
ToRecipient: Text[250];
trigger OnAfterGetRecord()
var
EmailMessage: Codeunit "Email Message";
RecRef: RecordRef;
FldRef: FieldRef;
ToRecipientList: List of [Text];
Recipient: Text;
begin
Clear(ToRecipient);
RecRef.Open(Database::"Sent Email");
FldRef := RecRef.Field(1);
FldRef.SetRange(Rec.Id);
FldRef := RecRef.Field(2);
if RecRef.FindFirst() then
if not IsNullGuid(FldRef.Value) then begin
if EmailMessage.Get(FldRef.Value) then begin
EmailMessage.GetRecipients(Enum::"Email Recipient Type"::"To", ToRecipientList);
foreach Recipient in ToRecipientList do
ToRecipient += ';' + Recipient;
ToRecipient := ToRecipient.TrimStart(';'); // trim extra semicolon
end;
end;
end;
}END
Hope this will help.
Thanks for reading.
ZHU




コメント