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 @@ -5,6 +5,9 @@

namespace System.Agents;

using System.IO;
using System.Utilities;

codeunit 4308 "Agent Message Impl."
{
Access = Internal;
Expand All @@ -13,6 +16,7 @@ codeunit 4308 "Agent Message Impl."

var
GlobalIgnoreAttachment: Boolean;
AttachmentsFilenameLbl: Label 'attachments_task%1_msg%2.zip', Comment = 'Filename format for downloading multiple attachments as a zip file. %1 = Task ID, %2 = Message ID';

procedure GetText(var AgentTaskMessage: Record "Agent Task Message"): Text
var
Expand Down Expand Up @@ -94,15 +98,47 @@ codeunit 4308 "Agent Message Impl."
procedure DownloadAttachments(var AgentTaskMessage: Record "Agent Task Message")
var
AgentTaskMessageAttachment: Record "Agent Task Message Attachment";
AgentTaskFile: Record "Agent Task File";
DataCompression: Codeunit "Data Compression";
TempBlob: Codeunit "Temp Blob";
AgentTaskImpl: Codeunit "Agent Task Impl.";
FileInStream: InStream;
ZipOutStream: OutStream;
ZipInStream: InStream;
FileName: Text;
AttachmentCount: Integer;
DownloadDialogTitleLbl: Label 'Download Email Attachment';
begin
AgentTaskMessageAttachment.SetRange("Task ID", AgentTaskMessage."Task ID");
AgentTaskMessageAttachment.SetRange("Message ID", AgentTaskMessage.ID);
if not AgentTaskMessageAttachment.FindSet() then
exit;

repeat
// Count attachments
AttachmentCount := AgentTaskMessageAttachment.Count();

// If single file, download directly
if AttachmentCount = 1 then begin
ShowOrDownloadAttachment(AgentTaskMessageAttachment."Task ID", AgentTaskMessageAttachment."File ID", true);
exit;
end;

// If multiple files, create a zip
DataCompression.CreateZipArchive();
repeat
if AgentTaskFile.Get(AgentTaskMessageAttachment."Task ID", AgentTaskMessageAttachment."File ID") then begin
AgentTaskFile.CalcFields(Content);
AgentTaskFile.Content.CreateInStream(FileInStream, AgentTaskImpl.GetDefaultEncoding());
DataCompression.AddEntry(FileInStream, AgentTaskFile."File Name");
end;
until AgentTaskMessageAttachment.Next() = 0;

TempBlob.CreateOutStream(ZipOutStream);
DataCompression.SaveZipArchive(ZipOutStream);
DataCompression.CloseZipArchive();
TempBlob.CreateInStream(ZipInStream);
FileName := StrSubstNo(AttachmentsFilenameLbl, Format(AgentTaskMessage."Task ID"), Format(AgentTaskMessage.ID));
File.DownloadFromStream(ZipInStream, DownloadDialogTitleLbl, '', '', FileName);
end;

procedure ShowOrDownloadAttachment(TaskID: BigInteger; FileID: BigInteger; ForceDownloadAttachment: Boolean)
Expand Down
12 changes: 12 additions & 0 deletions src/System Application/App/Agent/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@
"name": "DotNet Aliases",
"publisher": "Microsoft",
"version": "27.2.0.0"
},
{
"id": "e31ad830-3d46-472e-afeb-1d3d35247943",
"name": "BLOB Storage",
"publisher": "Microsoft",
"version": "27.2.0.0"
},
{
"id": "008c9419-0c3b-4d08-b03e-84e3adca689f",
"name": "Data Compression",
"publisher": "Microsoft",
"version": "27.2.0.0"
}
],
"propagateDependencies": true,
Expand Down
Loading