Skip to content

Commit 91168a7

Browse files
authored
[Agent] Add API to add attachment to task message (#3327)
<!-- 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 --> Add agent message API to add attachment to task message. #### 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#547967](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/547967)
1 parent 8dbc194 commit 91168a7

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

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

+14
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ codeunit 4307 "Agent Message"
6161
AgentMessageImpl.SetStatusToSent(AgentTaskMessage);
6262
end;
6363

64+
/// <summary>
65+
/// Add an attachment to the task message.
66+
/// </summary>
67+
/// <param name="FileName">The name of the file to be attached.</param>
68+
/// <param name="FileMIMEType">The MIME type of the file to be attached.</param>
69+
/// <param name="Attachment">The attachment stream.</param>
70+
[Scope('OnPrem')]
71+
procedure AddAttachment(var AgentTaskMessage: Record "Agent Task Message"; FileName: Text[250]; FileMIMEType: Text[100]; Attachment: InStream)
72+
var
73+
AgentMessageImpl: Codeunit "Agent Message Impl.";
74+
begin
75+
AgentMessageImpl.AddAttachment(AgentTaskMessage, FileName, FileMIMEType, Attachment);
76+
end;
77+
6478
/// <summary>
6579
/// Downloads the attachments for a specific message.
6680
/// </summary>

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

+22
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,28 @@ codeunit 4308 "Agent Message Impl."
4747
UpdateAgentTaskMessageStatus(AgentTaskMessage, AgentTaskMessage.Status::Sent);
4848
end;
4949

50+
procedure AddAttachment(var AgentTaskMessage: Record "Agent Task Message"; FileName: Text[250]; FileMIMEType: Text[100]; InStream: InStream)
51+
var
52+
AgentTaskFile: Record "Agent Task File";
53+
AgentTaskMessageAttachment: Record "Agent Task Message Attachment";
54+
AgentTaskImpl: Codeunit "Agent Task Impl.";
55+
OutStream: OutStream;
56+
begin
57+
// Add attachment to task file
58+
AgentTaskFile."Task ID" := AgentTaskMessage."Task ID";
59+
AgentTaskFile."File Name" := FileName;
60+
AgentTaskFile."File MIME Type" := FileMIMEType;
61+
AgentTaskFile.Content.CreateOutStream(OutStream, AgentTaskImpl.GetDefaultEncoding());
62+
CopyStream(OutStream, InStream);
63+
AgentTaskFile.Insert();
64+
65+
// Link task file to task message
66+
AgentTaskMessageAttachment."Task ID" := AgentTaskMessage."Task ID";
67+
AgentTaskMessageAttachment."Message ID" := AgentTaskMessage.ID;
68+
AgentTaskMessageAttachment."File ID" := AgentTaskFile.ID;
69+
AgentTaskMessageAttachment.Insert();
70+
end;
71+
5072
procedure DownloadAttachments(var AgentTaskMessage: Record "Agent Task Message")
5173
var
5274
AgentTaskFile: Record "Agent Task File";

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
namespace System.Agents;
77

8-
using System.Integration;
98
using System.Environment;
9+
using System.Integration;
1010

1111
codeunit 4300 "Agent Task Impl."
1212
{

0 commit comments

Comments
 (0)