Skip to content

Commit be9828a

Browse files
authored
[SOA] Enhance attachment handling in agent task messages with ignored reason support (#7786)
<!-- Thank you for submitting a Pull Request. If you're new to contributing to BCApps please read our pull request guideline below * https://github.com/microsoft/BCApps/Contributing.md --> #### Summary <!-- Provide a general summary of your changes --> This PR adds support for tracking and populating the ignored reason when handling attachments in agent task messages. **Changes:** - Modified `AgentTaskMessageBuilder.Codeunit.al `to expose ignored reason functionality - Updated `AgentMessageImpl.Codeunit.al` to handle ignored reason in attachment processing - Enhanced `AgentTaskMsgBuilderImpl.Codeunit.al` to populate ignored reason for attachments #### Work Item(s) <!-- Add the issue number here after the #. The issue needs to be open and approved. Submitting PRs with no linked issues or unapproved issues is highly discouraged. --> Fixes [AB#629496](https://dynamicssmb2.visualstudio.com/Dynamics%20SMB/_workitems/edit/629496)
1 parent 0313434 commit be9828a

3 files changed

Lines changed: 42 additions & 4 deletions

File tree

src/System Application/App/Agent/Interaction/AgentTaskMessageBuilder.Codeunit.al

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,24 @@ codeunit 4316 "Agent Task Message Builder"
199199
exit(this);
200200
end;
201201

202+
/// <summary>
203+
/// Attach a file to the task message.
204+
/// The file will be attached when the message is created.
205+
/// It is possible to attach multiple files to the message.
206+
/// </summary>
207+
/// <param name="FileName">The name of the file to attach.</param>
208+
/// <param name="FileMIMEType">The MIME type of the file to attach.</param>
209+
/// <param name="InStream">The stream of the file to attach.</param>
210+
/// <param name="Ignored">Specifies if the attachment should be marked as ignored, so that it is not processed by agent.</param>
211+
/// <param name="IgnoredReason">Specifies why the attachment was ignored.</param>
212+
/// <returns>This instance of the Agent Task Message Builder.</returns>
213+
procedure AddAttachment(FileName: Text[250]; FileMIMEType: Text[100]; InStream: InStream; Ignored: Boolean; IgnoredReason: Text[250]): codeunit "Agent Task Message Builder"
214+
begin
215+
FeatureAccessManagement.AgentTaskManagementPreviewEnabled(true);
216+
AgentTaskMsgBuilderImpl.AddAttachment(FileName, FileMIMEType, InStream, Ignored, IgnoredReason);
217+
exit(this);
218+
end;
219+
202220
/// <summary>
203221
/// Attach a file to the task message.
204222
/// The file will be attached when the message is created.

src/System Application/App/Agent/Interaction/Internal/AgentMessageImpl.Codeunit.al

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ codeunit 4308 "Agent Message Impl."
5959
GlobalIgnoreAttachment := IgnoreAttachment;
6060
end;
6161

62-
procedure AddAttachment(var AgentTaskMessage: Record "Agent Task Message"; var TempAgentTaskFile: Record "Agent Task File" temporary)
62+
procedure AddAttachment(var AgentTaskMessage: Record "Agent Task Message"; var TempAgentTaskFile: Record "Agent Task File" temporary; IgnoredReason: Text[250])
6363
var
6464
AgentTaskImpl: Codeunit "Agent Task Impl.";
6565
FileInstream: InStream;
@@ -69,10 +69,15 @@ codeunit 4308 "Agent Message Impl."
6969
exit;
7070

7171
TempAgentTaskFile.Content.CreateInStream(FileInstream, AgentTaskImpl.GetDefaultEncoding());
72-
AddAttachment(AgentTaskMessage, TempAgentTaskFile."File Name", TempAgentTaskFile."File MIME Type", FileInstream);
72+
AddAttachment(AgentTaskMessage, TempAgentTaskFile."File Name", TempAgentTaskFile."File MIME Type", FileInstream, IgnoredReason);
7373
end;
7474

7575
procedure AddAttachment(var AgentTaskMessage: Record "Agent Task Message"; FileName: Text[250]; FileMIMEType: Text[100]; InStream: InStream)
76+
begin
77+
AddAttachment(AgentTaskMessage, FileName, FileMIMEType, InStream, '');
78+
end;
79+
80+
procedure AddAttachment(var AgentTaskMessage: Record "Agent Task Message"; FileName: Text[250]; FileMIMEType: Text[100]; InStream: InStream; IgnoredReason: Text[250])
7681
var
7782
AgentTaskFile: Record "Agent Task File";
7883
AgentTaskMessageAttachment: Record "Agent Task Message Attachment";
@@ -92,6 +97,7 @@ codeunit 4308 "Agent Message Impl."
9297
AgentTaskMessageAttachment."Message ID" := AgentTaskMessage.ID;
9398
AgentTaskMessageAttachment."File ID" := AgentTaskFile.ID;
9499
AgentTaskMessageAttachment.Ignored := GlobalIgnoreAttachment;
100+
AgentTaskMessageAttachment."Ignored Reason" := CopyStr(IgnoredReason, 1, MaxStrLen(AgentTaskMessageAttachment."Ignored Reason"));
95101
AgentTaskMessageAttachment.Insert();
96102
end;
97103

src/System Application/App/Agent/Interaction/Internal/AgentTaskMsgBuilderImpl.Codeunit.al

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ codeunit 4311 "Agent Task Msg. Builder Impl."
1818
GlobalAgentTask: Record "Agent Task";
1919
GlobalAgentTaskMessage: Record "Agent Task Message";
2020
GlobalIgnoreAttachmentsList: Dictionary of [BigInteger, Boolean];
21+
GlobalIgnoredReasonByFileId: Dictionary of [BigInteger, Text[250]];
2122
GlobalFrom: Text[250];
2223
GlobalMessageExternalID: Text[2048];
2324
GlobalMessageText: Text;
@@ -95,6 +96,7 @@ codeunit 4311 "Agent Task Msg. Builder Impl."
9596
AgentTaskImpl: Codeunit "Agent Task Impl.";
9697
AgentMessageImpl: Codeunit "Agent Message Impl.";
9798
IgnoreAttachment: Boolean;
99+
IgnoredReason: Text[250];
98100
MessageText: Text;
99101
begin
100102
VerifyMandatoryFieldsSet();
@@ -108,8 +110,11 @@ codeunit 4311 "Agent Task Msg. Builder Impl."
108110
IgnoreAttachment := false;
109111
if GlobalIgnoreAttachmentsList.ContainsKey(TempAgentTaskFileToAttach.ID) then
110112
IgnoreAttachment := GlobalIgnoreAttachmentsList.Get(TempAgentTaskFileToAttach.ID);
113+
IgnoredReason := '';
114+
if GlobalIgnoredReasonByFileId.ContainsKey(TempAgentTaskFileToAttach.ID) then
115+
IgnoredReason := GlobalIgnoredReasonByFileId.Get(TempAgentTaskFileToAttach.ID);
111116
AgentMessageImpl.SetIgnoreAttachment(GlobalIgnoreAttachment or IgnoreAttachment);
112-
AgentMessageImpl.AddAttachment(GlobalAgentTaskMessage, TempAgentTaskFileToAttach);
117+
AgentMessageImpl.AddAttachment(GlobalAgentTaskMessage, TempAgentTaskFileToAttach, IgnoredReason);
113118
until TempAgentTaskFileToAttach.Next() = 0;
114119

115120
if SetTaskStatusToReady then
@@ -127,12 +132,19 @@ codeunit 4311 "Agent Task Msg. Builder Impl."
127132
[Scope('OnPrem')]
128133
procedure AddAttachment(FileName: Text[250]; FileMIMEType: Text[100]; InStream: InStream): codeunit "Agent Task Msg. Builder Impl."
129134
begin
130-
AddAttachment(FileName, FileMIMEType, InStream, false);
135+
AddAttachment(FileName, FileMIMEType, InStream, false, '');
131136
exit(this);
132137
end;
133138

134139
[Scope('OnPrem')]
135140
procedure AddAttachment(FileName: Text[250]; FileMIMEType: Text[100]; InStream: InStream; Ignored: Boolean): codeunit "Agent Task Msg. Builder Impl."
141+
begin
142+
AddAttachment(FileName, FileMIMEType, InStream, Ignored, '');
143+
exit(this);
144+
end;
145+
146+
[Scope('OnPrem')]
147+
procedure AddAttachment(FileName: Text[250]; FileMIMEType: Text[100]; InStream: InStream; Ignored: Boolean; IgnoredReason: Text[250]): codeunit "Agent Task Msg. Builder Impl."
136148
var
137149
FileOutStream: OutStream;
138150
begin
@@ -146,6 +158,8 @@ codeunit 4311 "Agent Task Msg. Builder Impl."
146158
TempAgentTaskFileToAttach.Modify();
147159

148160
GlobalIgnoreAttachmentsList.Add(TempAgentTaskFileToAttach.ID, Ignored);
161+
if Ignored then
162+
GlobalIgnoredReasonByFileId.Add(TempAgentTaskFileToAttach.ID, IgnoredReason);
149163
exit(this);
150164
end;
151165

0 commit comments

Comments
 (0)