Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ table 4585 "SOA Email"
key(Key2; "Agent User Security ID", Processed)
{
}
key(Key3; "Task ID", "Task Message ID")
{
}
}

internal procedure SetAgentMessageFields(var AgentTaskMessage: Record "Agent Task Message")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ page 4404 "SOA Email Message"
Editable = false;
}
}
group(CcGroup)
Comment thread
attilatoury marked this conversation as resolved.
{
ShowCaption = false;

field(MessageCc; GlobalCcRecipients)
Comment thread
attilatoury marked this conversation as resolved.
{
Caption = 'Cc';
ToolTip = 'Specifies the email CC recipients.';
Editable = false;
Importance = Additional;
}
}
group(UnknownContact)
{
ShowCaption = false;
Expand Down Expand Up @@ -341,6 +353,7 @@ page 4404 "SOA Email Message"
begin
GlobalMessageText := AgentMessage.GetText(Rec);
GlobalPreviousMessageText := SOATaskMessage.GetPreviousText(Rec);
GlobalCcRecipients := SOATaskMessage.GetMessageCcRecipients(Rec);
Comment thread
attilatoury marked this conversation as resolved.
PreviousMessagesVisible := GlobalPreviousMessageText <> '';
IsMessageEditable := AgentMessage.IsEditable(Rec);
AttachmentCount := SOAEmailSetup.GetNumberOfAttachments(Rec);
Expand Down Expand Up @@ -498,6 +511,7 @@ page 4404 "SOA Email Message"
FromGroupVisible: Boolean;
ToGroupVisible: Boolean;
GlobalSendToAddress: Text;
GlobalCcRecipients: Text;
GlobalMessageText: Text;
GlobalPreviousMessageText: Text;
PreviousMessagesVisible: Boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ using System.Telemetry;
codeunit 4419 "SOA Send Reply"
{
Access = Internal;
Permissions = tabledata "Email Inbox" = r;
InherentEntitlements = X;
InherentPermissions = X;
TableNo = "Agent Task Message";
Expand Down Expand Up @@ -111,6 +112,20 @@ codeunit 4419 "SOA Send Reply"
exit('');
end;

[TryFunction]
internal procedure TryGetMappedReplyCcRecipients(InputAgentTaskMessage: Record "Agent Task Message"; var CCRecipients: List of [Text]; var IsMappedReply: Boolean)
var
ToRecipients: List of [Text];
MappedContactEmail: Text;
begin
Clear(CCRecipients);
Clear(IsMappedReply);
MappedContactEmail := GetMappedContactEmail(InputAgentTaskMessage);
IsMappedReply := MappedContactEmail <> '';
if IsMappedReply then
GetMappedReplyRecipients(InputAgentTaskMessage, MappedContactEmail, ToRecipients, CCRecipients);
end;

/// <summary>
/// Ensures that a mapped reply belongs to the selected SOA setup and is sent by its configured owner or agent.
/// Mapped replies redirect the original thread, so this check is enforced independently of the codeunit's internal access.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ namespace Microsoft.Agent.SalesOrderAgent;

using Microsoft.CRM.Contact;
using System.Agents;
using System.Email;

codeunit 4398 "SOA Task Message"
{
Access = Internal;
Permissions = tabledata "Email Inbox" = r;
InherentEntitlements = X;
InherentPermissions = X;

Expand Down Expand Up @@ -121,6 +123,56 @@ codeunit 4398 "SOA Task Message"
exit(true);
end;

internal procedure GetMessageCcRecipients(AgentTaskMessage: Record "Agent Task Message"): Text
Comment thread
attilatoury marked this conversation as resolved.
Comment thread
attilatoury marked this conversation as resolved.
var
SourceAgentTaskMessage: Record "Agent Task Message";
SOAEmail: Record "SOA Email";
EmailInbox: Record "Email Inbox";
EmailMessage: Codeunit "Email Message";
SOASendReply: Codeunit "SOA Send Reply";
CcRecipients: List of [Text];
IsMappedReply: Boolean;
begin
SourceAgentTaskMessage := AgentTaskMessage;
if AgentTaskMessage.Type = AgentTaskMessage.Type::Output then begin
if not SourceAgentTaskMessage.Get(AgentTaskMessage."Task ID", AgentTaskMessage."Input Message ID") then
exit('');
Comment on lines +137 to +139

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$\textbf{🟡\ Medium\ Severity\ —\ Performance}$

GetMessageCcRecipients fetches the full Agent Task Message row via SourceAgentTaskMessage.Get(...) when Type = Output, but only the From field (used indirectly by TryGetMappedReplyCcRecipients -> GetMappedContactEmail) plus the primary-key fields (already loaded regardless) are needed from that record in this code path. Add SetLoadFields(From) before the Get call to avoid materializing the rest of the record unnecessarily, matching the partial-record-load guidance already applied elsewhere in this codeunit (e.g. SOAEmail.SetLoadFields("Email Inbox ID")).

Suggested change
if AgentTaskMessage.Type = AgentTaskMessage.Type::Output then begin
if not SourceAgentTaskMessage.Get(AgentTaskMessage."Task ID", AgentTaskMessage."Input Message ID") then
exit('');
if AgentTaskMessage.Type = AgentTaskMessage.Type::Output then begin
SourceAgentTaskMessage.SetLoadFields(From);
if not SourceAgentTaskMessage.Get(AgentTaskMessage."Task ID", AgentTaskMessage."Input Message ID") then
exit('');

Knowledge:

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.41.6

if not SOASendReply.TryGetMappedReplyCcRecipients(SourceAgentTaskMessage, CcRecipients, IsMappedReply) then
exit('');
if IsMappedReply then
exit(RecipientsToText(CcRecipients));
end;

SOAEmail.SetLoadFields("Email Inbox ID");
SOAEmail.SetRange("Task ID", SourceAgentTaskMessage."Task ID");
Comment thread
attilatoury marked this conversation as resolved.
SOAEmail.SetRange("Task Message ID", SourceAgentTaskMessage.ID);
if not SOAEmail.FindFirst() then
exit('');
Comment thread
attilatoury marked this conversation as resolved.

EmailInbox.SetLoadFields("Message Id");
if not EmailInbox.Get(SOAEmail."Email Inbox ID") then
exit('');
if not EmailMessage.Get(EmailInbox."Message Id") then
exit('');

EmailMessage.GetRecipients(Enum::"Email Recipient Type"::Cc, CcRecipients);
exit(RecipientsToText(CcRecipients));
end;

local procedure RecipientsToText(Recipients: List of [Text]): Text
var
Recipient: Text;
RecipientsTextBuilder: TextBuilder;
begin
foreach Recipient in Recipients do begin
if RecipientsTextBuilder.Length() > 0 then
RecipientsTextBuilder.Append(';');
RecipientsTextBuilder.Append(Recipient);
end;

exit(RecipientsTextBuilder.ToText());
end;

internal procedure MessageRequiresReview(SOASetup: Record "SOA Setup"; SenderAddress: Text; IsFirstMessageInTask: Boolean): Boolean
var
SOAFiltersImpl: Codeunit "SOA Filters Impl.";
Expand Down
Loading