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 @@ -18,6 +18,21 @@ codeunit 4307 "Agent Message"
/// <summary>
/// Get the message text for the given agent task message.
/// </summary>
/// <param name="TaskID">The task ID of the message.</param>
/// <param name="MessageID">The unique identifier of the message.</param>
/// <returns>The body of the agent task message.</returns>
procedure GetText(TaskID: BigInteger; MessageID: Guid): Text
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is hard to know from the caller what the argument True means here. Should we have a "wrapper" function where it is clear from the name and the argument is fixed to true?

exit(AgentMessageImpl.GetText(TaskID, MessageID));
end;

/// <summary>
/// Get the message text for the given agent task message.
/// The record is not retrieved again; the caller must ensure the record is up to date.
/// </summary>
/// <param name="AgentTaskMessage">Agent task message.</param>
/// <returns>The body of the agent task message.</returns>
procedure GetText(var AgentTaskMessage: Record "Agent Task Message"): Text
Expand All @@ -31,6 +46,24 @@ codeunit 4307 "Agent Message"
/// <summary>
/// Updates the message text.
/// </summary>
/// <param name="TaskID">The task ID of the message.</param>
/// <param name="MessageID">The unique identifier of the message.</param>
/// <param name="NewMessageText">New message text to set.</param>
procedure UpdateText(TaskID: BigInteger; MessageID: Guid; NewMessageText: Text)
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
AgentMessageImpl.UpdateText(TaskID, MessageID, NewMessageText);
end;

/// <summary>
/// Updates the message text.
/// </summary>
/// <remarks>
/// This method will be marked as obsolete soon:
/// [Obsolete('Use the overload that takes TaskID and MessageID instead.', '30.0')]
/// </remarks>
/// <param name="AgentTaskMessage">The message record to update.</param>
/// <param name="NewMessageText">New message text to set.</param>
procedure UpdateText(var AgentTaskMessage: Record "Agent Task Message"; NewMessageText: Text)
Expand All @@ -44,6 +77,21 @@ codeunit 4307 "Agent Message"
/// <summary>
/// Check if it is possible to edit the message.
/// </summary>
/// <param name="TaskID">The task ID of the message.</param>
/// <param name="MessageID">The unique identifier of the message.</param>
/// <returns>If it is possible to change the message.</returns>
procedure IsEditable(TaskID: BigInteger; MessageID: Guid): Boolean
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
exit(AgentMessageImpl.IsEditable(TaskID, MessageID));
end;

/// <summary>
/// Check if it is possible to edit the message.
/// The record is not retrieved again; the caller must ensure the record is up to date.
/// </summary>
/// <param name="AgentTaskMessage">Agent task message to verify.</param>
/// <returns>If it is possible to change the message.</returns>
procedure IsEditable(var AgentTaskMessage: Record "Agent Task Message"): Boolean
Expand All @@ -57,6 +105,23 @@ codeunit 4307 "Agent Message"
/// <summary>
/// Sets the message status to sent.
/// </summary>
/// <param name="TaskID">The task ID of the message.</param>
/// <param name="MessageID">The unique identifier of the message.</param>
procedure SetStatusToSent(TaskID: BigInteger; MessageID: Guid)
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
AgentMessageImpl.SetStatusToSent(TaskID, MessageID);
end;

/// <summary>
/// Sets the message status to sent.
/// </summary>
/// <remarks>
/// This method will be marked as obsolete soon:
/// [Obsolete('Use the overload that takes TaskID and MessageID instead.', '30.0')]
/// </remarks>
/// <param name="AgentTaskMessage">Agent task message to update status.</param>
procedure SetStatusToSent(var AgentTaskMessage: Record "Agent Task Message")
var
Expand Down
108 changes: 108 additions & 0 deletions src/System Application/App/Agent/Interaction/AgentTask.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,23 @@ codeunit 4303 "Agent Task"
/// Set the status of the task to ready if the task is in the state that it can be started again.
/// The agent task will be be picked up for processing shortly after updating the status.
/// </summary>
/// <param name="AgentTaskID">The ID of the agent task to set to ready.</param>
procedure SetStatusToReady(AgentTaskID: BigInteger)
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
AgentTaskImpl.SetTaskStatusToReadyIfPossible(AgentTaskID);
end;

/// <summary>
/// Set the status of the task to ready if the task is in the state that it can be started again.
/// The agent task will be be picked up for processing shortly after updating the status.
/// </summary>
/// <remarks>
/// This method will be marked as obsolete soon:
/// [Obsolete('Use the overload that takes AgentTaskID instead.', '30.0')]
/// </remarks>
/// <param name="AgentTask">The agent task to set to ready.</param>
/// <returns>The agent task with the status set to ready.</returns>
procedure SetStatusToReady(var AgentTask: Record "Agent Task")
Expand All @@ -60,6 +77,20 @@ codeunit 4303 "Agent Task"
/// <summary>
/// Checks if the task can be set to ready and started again.
/// </summary>
/// <param name="AgentTaskID">The ID of the agent task to check.</param>
/// <returns>True if agent task can be set to ready, false otherwise</returns>
procedure CanSetStatusToReady(AgentTaskID: BigInteger): Boolean
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
exit(AgentTaskImpl.CanAgentTaskBeSetToReady(AgentTaskID));
end;

/// <summary>
/// Checks if the task can be set to ready and started again.
/// The record is not retrieved again; the caller must ensure the record is up to date.
/// </summary>
/// <param name="AgentTask">The agent task to check.</param>
/// <returns>True if agent task can be set to ready, false otherwise</returns>
procedure CanSetStatusToReady(AgentTask: Record "Agent Task"): Boolean
Expand All @@ -73,6 +104,24 @@ codeunit 4303 "Agent Task"
/// <summary>
/// Stops the agent task.
/// </summary>
/// <param name="AgentTaskID">The ID of the agent task to stop.</param>
/// <param name="UserConfirm">Whether to show a confirmation dialog to the user.</param>
procedure StopTask(AgentTaskID: BigInteger; UserConfirm: Boolean)
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
TaskStatus: Enum "Agent Task Status";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
AgentTaskImpl.StopTask(AgentTaskID, TaskStatus::"Stopped by User", UserConfirm);
end;

/// <summary>
/// Stops the agent task.
/// </summary>
/// <remarks>
/// This method will be marked as obsolete soon:
/// [Obsolete('Use the overload that takes AgentTaskID instead.', '30.0')]
/// </remarks>
/// <param name="AgentTask">The agent task to stop.</param>
/// <param name="UserConfirm">Whether to show a confirmation dialog to the user.</param>
procedure StopTask(var AgentTask: Record "Agent Task"; UserConfirm: Boolean)
Expand All @@ -87,6 +136,23 @@ codeunit 4303 "Agent Task"
/// <summary>
/// Restarts the agent task by setting its status to ready.
/// </summary>
/// <param name="AgentTaskID">The ID of the agent task to restart.</param>
/// <param name="UserConfirm">Whether to show a confirmation dialog to the user.</param>
procedure RestartTask(AgentTaskID: BigInteger; UserConfirm: Boolean)
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
AgentTaskImpl.RestartTask(AgentTaskID, UserConfirm);
end;

/// <summary>
/// Restarts the agent task by setting its status to ready.
/// </summary>
/// <remarks>
/// This method will be marked as obsolete soon:
/// [Obsolete('Use the overload that takes AgentTaskID instead.', '30.0')]
/// </remarks>
/// <param name="AgentTask">The agent task to restart.</param>
/// <param name="UserConfirm">Whether to show a confirmation dialog to the user.</param>
procedure RestartTask(var AgentTask: Record "Agent Task"; UserConfirm: Boolean)
Expand All @@ -100,6 +166,20 @@ codeunit 4303 "Agent Task"
/// <summary>
/// Checks if the agent task is currently running.
/// </summary>
/// <param name="AgentTaskID">The ID of the agent task to check.</param>
/// <returns>True if the task is running, false otherwise.</returns>
procedure IsTaskRunning(AgentTaskID: BigInteger): Boolean
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
exit(AgentTaskImpl.IsTaskRunning(AgentTaskID));
end;

/// <summary>
/// Checks if the agent task is currently running.
/// The record is not retrieved again; the caller must ensure the record is up to date.
/// </summary>
/// <param name="AgentTask">The agent task to check.</param>
/// <returns>True if the task is running, false otherwise.</returns>
procedure IsTaskRunning(var AgentTask: Record "Agent Task"): Boolean
Expand All @@ -113,6 +193,20 @@ codeunit 4303 "Agent Task"
/// <summary>
/// Checks if the agent task is completed.
/// </summary>
/// <param name="AgentTaskID">The ID of the agent task to check.</param>
/// <returns>True if the task is completed, false otherwise.</returns>
procedure IsTaskCompleted(AgentTaskID: BigInteger): Boolean
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
exit(AgentTaskImpl.IsTaskCompleted(AgentTaskID));
end;

/// <summary>
/// Checks if the agent task is completed.
/// The record is not retrieved again; the caller must ensure the record is up to date.
/// </summary>
/// <param name="AgentTask">The agent task to check.</param>
/// <returns>True if the task is completed, false otherwise.</returns>
procedure IsTaskCompleted(var AgentTask: Record "Agent Task"): Boolean
Expand All @@ -126,6 +220,20 @@ codeunit 4303 "Agent Task"
/// <summary>
/// Checks if the agent task is stopped (by user or system).
/// </summary>
/// <param name="AgentTaskID">The ID of the agent task to check.</param>
/// <returns>True if the task is stopped, false otherwise.</returns>
procedure IsTaskStopped(AgentTaskID: BigInteger): Boolean
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
begin
FeatureAccessManagement.AgentManagementAllowed(true);
exit(AgentTaskImpl.IsTaskStopped(AgentTaskID));
end;

/// <summary>
/// Checks if the agent task is stopped (by user or system).
/// The record is not retrieved again; the caller must ensure the record is up to date.
/// </summary>
/// <param name="AgentTask">The agent task to check.</param>
/// <returns>True if the task is stopped, false otherwise.</returns>
procedure IsTaskStopped(var AgentTask: Record "Agent Task"): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ codeunit 4316 "Agent Task Message Builder"
/// <returns>This instance of the Agent Task Message Builder.</returns>
procedure AddAttachment(FileName: Text[250]; FileMIMEType: Text[100]; InStream: InStream; Ignored: Boolean; IgnoredReason: Text[250]): codeunit "Agent Task Message Builder"
begin
FeatureAccessManagement.AgentTaskManagementPreviewEnabled(true);
FeatureAccessManagement.AgentManagementAllowed(true);
AgentTaskMsgBuilderImpl.AddAttachment(FileName, FileMIMEType, InStream, Ignored, IgnoredReason);
exit(this);
end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ codeunit 4308 "Agent Message Impl."
GlobalIgnoreAttachment: Boolean;
AttachmentsFilenameLbl: Label 'attachments_task%1_%2.zip', Comment = 'Filename format for downloading multiple attachments as a zip file. %1 = task ID, %2 = date/time stamp', Locked = true;

procedure GetText(TaskID: BigInteger; MessageID: Guid): Text
var
AgentTaskMessage: Record "Agent Task Message";
begin
AgentTaskMessage.Get(TaskID, MessageID);
exit(GetText(AgentTaskMessage));
end;

procedure GetText(var AgentTaskMessage: Record "Agent Task Message"): Text
Comment thread
qutreson marked this conversation as resolved.
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
Expand All @@ -30,15 +38,35 @@ codeunit 4308 "Agent Message Impl."
exit(ContentText);
end;

procedure UpdateText(TaskID: BigInteger; MessageID: Guid; NewMessageText: Text)
var
AgentTaskMessage: Record "Agent Task Message";
begin
AgentTaskMessage."Task ID" := TaskID;
AgentTaskMessage.ID := MessageID;
UpdateText(AgentTaskMessage, NewMessageText);
end;

procedure UpdateText(var AgentTaskMessage: Record "Agent Task Message"; NewMessageText: Text)
Comment thread
BazookaMusic marked this conversation as resolved.
var
AgentTaskMessageToModify: Record "Agent Task Message";
AgentTaskImpl: Codeunit "Agent Task Impl.";
ContentOutStream: OutStream;
begin
Clear(AgentTaskMessage.Content);
AgentTaskMessage.Content.CreateOutStream(ContentOutStream, AgentTaskImpl.GetDefaultEncoding());
AgentTaskMessageToModify.Get(AgentTaskMessage."Task ID", AgentTaskMessage.ID);
AgentTaskMessageToModify.Content.CreateOutStream(ContentOutStream, AgentTaskImpl.GetDefaultEncoding());
ContentOutStream.Write(NewMessageText);
AgentTaskMessage.Modify(true);
AgentTaskMessageToModify.Modify(true);

AgentTaskMessage.Content := AgentTaskMessageToModify.Content;
end;

procedure IsEditable(TaskID: BigInteger; MessageID: Guid): Boolean
Comment thread
qutreson marked this conversation as resolved.
var
AgentTaskMessage: Record "Agent Task Message";
begin
AgentTaskMessage.Get(TaskID, MessageID);
exit(IsEditable(AgentTaskMessage));
end;

procedure IsEditable(var AgentTaskMessage: Record "Agent Task Message"): Boolean
Expand All @@ -49,6 +77,15 @@ codeunit 4308 "Agent Message Impl."
exit((AgentTaskMessage.Status = AgentTaskMessage.Status::Draft) or (AgentTaskMessage.Status = AgentTaskMessage.Status::" "));
end;

procedure SetStatusToSent(TaskID: BigInteger; MessageID: Guid)
var
AgentTaskMessage: Record "Agent Task Message";
begin
AgentTaskMessage."Task ID" := TaskID;
AgentTaskMessage.ID := MessageID;
SetStatusToSent(AgentTaskMessage);
end;

procedure SetStatusToSent(var AgentTaskMessage: Record "Agent Task Message")
begin
UpdateStatus(AgentTaskMessage, AgentTaskMessage.Status::Sent);
Expand Down Expand Up @@ -210,10 +247,15 @@ codeunit 4308 "Agent Message Impl."
until AgentTaskMessageAttachment.Next() = 0;
end;

procedure UpdateStatus(var AgentTaskMessage: Record "Agent Task Message"; Status: Option)
local procedure UpdateStatus(var AgentTaskMessage: Record "Agent Task Message"; Status: Option)
var
AgentTaskMessageToModify: Record "Agent Task Message";
begin
AgentTaskMessage.Status := Status;
AgentTaskMessage.Modify(true);
AgentTaskMessageToModify.Get(AgentTaskMessage."Task ID", AgentTaskMessage.ID);
AgentTaskMessageToModify.Status := Status;
AgentTaskMessageToModify.Modify(true);

AgentTaskMessage.Status := AgentTaskMessageToModify.Status;
end;

procedure GetFileSizeDisplayText(SizeInBytes: Decimal): Text
Expand Down
Loading
Loading