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.AgentTaskManagementPreviewEnabled(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 @@ -28,22 +43,54 @@ codeunit 4307 "Agent Message"
exit(AgentMessageImpl.GetText(AgentTaskMessage));
end;

/// <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.AgentTaskManagementPreviewEnabled(true);
AgentMessageImpl.UpdateText(TaskID, MessageID, NewMessageText);
end;

#if not CLEAN30
/// <summary>
/// Updates the message text.
/// </summary>
/// <param name="AgentTaskMessage">The message record to update.</param>
/// <param name="NewMessageText">New message text to set.</param>
[Obsolete('Use the overload that takes TaskID and MessageID instead.', '30.0')]
procedure UpdateText(var AgentTaskMessage: Record "Agent Task Message"; NewMessageText: Text)
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
FeatureAccessManagement.AgentTaskManagementPreviewEnabled(true);
AgentMessageImpl.UpdateText(AgentTaskMessage, NewMessageText);
end;
#endif

/// <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.AgentTaskManagementPreviewEnabled(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 @@ -54,17 +101,33 @@ codeunit 4307 "Agent Message"
exit(AgentMessageImpl.IsEditable(AgentTaskMessage));
end;

/// <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.AgentTaskManagementPreviewEnabled(true);
AgentMessageImpl.SetStatusToSent(TaskID, MessageID);
end;

#if not CLEAN30
/// <summary>
/// Sets the message status to sent.
/// </summary>
/// <param name="AgentTaskMessage">Agent task message to update status.</param>
[Obsolete('Use the overload that takes TaskID and MessageID instead.', '30.0')]
procedure SetStatusToSent(var AgentTaskMessage: Record "Agent Task Message")
var
AgentMessageImpl: Codeunit "Agent Message Impl.";
begin
FeatureAccessManagement.AgentTaskManagementPreviewEnabled(true);
AgentMessageImpl.SetStatusToSent(AgentTaskMessage);
end;
#endif

/// <summary>
/// Add an attachment to the task message.
Expand Down
105 changes: 105 additions & 0 deletions src/System Application/App/Agent/Interaction/AgentTask.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,53 @@ codeunit 4303 "Agent Task"
exit(AgentTask);
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>
/// <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.AgentTaskManagementPreviewEnabled(true);
AgentTaskImpl.SetTaskStatusToReadyIfPossible(AgentTaskID);
end;

#if not CLEAN30
/// <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>
/// <param name="AgentTask">The agent task to set to ready.</param>
/// <returns>The agent task with the status set to ready.</returns>
[Obsolete('Use the overload that takes AgentTaskID instead.', '30.0')]
procedure SetStatusToReady(var AgentTask: Record "Agent Task")
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
begin
FeatureAccessManagement.AgentTaskManagementPreviewEnabled(true);
AgentTaskImpl.SetTaskStatusToReadyIfPossible(AgentTask);
end;
#endif

/// <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.AgentTaskManagementPreviewEnabled(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 @@ -70,11 +100,27 @@ codeunit 4303 "Agent Task"
exit(AgentTaskImpl.CanAgentTaskBeSetToReady(AgentTask));
end;

/// <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.AgentTaskManagementPreviewEnabled(true);
AgentTaskImpl.StopTask(AgentTaskID, TaskStatus::"Stopped by User", UserConfirm);
end;

#if not CLEAN30
/// <summary>
/// Stops the agent task.
/// </summary>
/// <param name="AgentTask">The agent task to stop.</param>
/// <param name="UserConfirm">Whether to show a confirmation dialog to the user.</param>
[Obsolete('Use the overload that takes AgentTaskID instead.', '30.0')]
procedure StopTask(var AgentTask: Record "Agent Task"; UserConfirm: Boolean)
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
Expand All @@ -83,23 +129,54 @@ codeunit 4303 "Agent Task"
FeatureAccessManagement.AgentTaskManagementPreviewEnabled(true);
AgentTaskImpl.StopTask(AgentTask, TaskStatus::"Stopped by User", UserConfirm);
end;
#endif

/// <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.AgentTaskManagementPreviewEnabled(true);
AgentTaskImpl.RestartTask(AgentTaskID, UserConfirm);
end;

#if not CLEAN30
/// <summary>
/// Restarts the agent task by setting its status to ready.
/// </summary>
/// <param name="AgentTask">The agent task to restart.</param>
/// <param name="UserConfirm">Whether to show a confirmation dialog to the user.</param>
[Obsolete('Use the overload that takes AgentTaskID instead.', '30.0')]
procedure RestartTask(var AgentTask: Record "Agent Task"; UserConfirm: Boolean)
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
begin
FeatureAccessManagement.AgentTaskManagementPreviewEnabled(true);
AgentTaskImpl.RestartTask(AgentTask, UserConfirm);
end;
#endif

/// <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.AgentTaskManagementPreviewEnabled(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 +190,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.AgentTaskManagementPreviewEnabled(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 +217,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.AgentTaskManagementPreviewEnabled(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 @@ -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
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
Expand All @@ -30,15 +38,34 @@ 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)
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.

Since this method changed behavior, should we have a unit test for it to ensure we are not modifying all fields, but only the content?

var
AgentTaskImpl: Codeunit "Agent Task Impl.";
AgentTaskMessageToModify: Record "Agent Task Message";
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
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 +76,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 @@ -204,10 +240,23 @@ codeunit 4308 "Agent Message Impl."
until AgentTaskMessageAttachment.Next() = 0;
end;

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

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