diff --git a/src/System Application/App/Agent/Interaction/AgentMessage.Codeunit.al b/src/System Application/App/Agent/Interaction/AgentMessage.Codeunit.al
index dbd34e876d..cc30268838 100644
--- a/src/System Application/App/Agent/Interaction/AgentMessage.Codeunit.al
+++ b/src/System Application/App/Agent/Interaction/AgentMessage.Codeunit.al
@@ -18,6 +18,21 @@ codeunit 4307 "Agent Message"
///
/// Get the message text for the given agent task message.
///
+ /// The task ID of the message.
+ /// The unique identifier of the message.
+ /// The body of the agent task message.
+ procedure GetText(TaskID: BigInteger; MessageID: Guid): Text
+ var
+ AgentMessageImpl: Codeunit "Agent Message Impl.";
+ begin
+ FeatureAccessManagement.AgentManagementAllowed(true);
+ exit(AgentMessageImpl.GetText(TaskID, MessageID));
+ end;
+
+ ///
+ /// 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.
+ ///
/// Agent task message.
/// The body of the agent task message.
procedure GetText(var AgentTaskMessage: Record "Agent Task Message"): Text
@@ -31,6 +46,24 @@ codeunit 4307 "Agent Message"
///
/// Updates the message text.
///
+ /// The task ID of the message.
+ /// The unique identifier of the message.
+ /// New message text to set.
+ procedure UpdateText(TaskID: BigInteger; MessageID: Guid; NewMessageText: Text)
+ var
+ AgentMessageImpl: Codeunit "Agent Message Impl.";
+ begin
+ FeatureAccessManagement.AgentManagementAllowed(true);
+ AgentMessageImpl.UpdateText(TaskID, MessageID, NewMessageText);
+ end;
+
+ ///
+ /// Updates the message text.
+ ///
+ ///
+ /// This method will be marked as obsolete soon:
+ /// [Obsolete('Use the overload that takes TaskID and MessageID instead.', '30.0')]
+ ///
/// The message record to update.
/// New message text to set.
procedure UpdateText(var AgentTaskMessage: Record "Agent Task Message"; NewMessageText: Text)
@@ -44,6 +77,21 @@ codeunit 4307 "Agent Message"
///
/// Check if it is possible to edit the message.
///
+ /// The task ID of the message.
+ /// The unique identifier of the message.
+ /// If it is possible to change the message.
+ procedure IsEditable(TaskID: BigInteger; MessageID: Guid): Boolean
+ var
+ AgentMessageImpl: Codeunit "Agent Message Impl.";
+ begin
+ FeatureAccessManagement.AgentManagementAllowed(true);
+ exit(AgentMessageImpl.IsEditable(TaskID, MessageID));
+ end;
+
+ ///
+ /// 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.
+ ///
/// Agent task message to verify.
/// If it is possible to change the message.
procedure IsEditable(var AgentTaskMessage: Record "Agent Task Message"): Boolean
@@ -57,6 +105,23 @@ codeunit 4307 "Agent Message"
///
/// Sets the message status to sent.
///
+ /// The task ID of the message.
+ /// The unique identifier of the message.
+ procedure SetStatusToSent(TaskID: BigInteger; MessageID: Guid)
+ var
+ AgentMessageImpl: Codeunit "Agent Message Impl.";
+ begin
+ FeatureAccessManagement.AgentManagementAllowed(true);
+ AgentMessageImpl.SetStatusToSent(TaskID, MessageID);
+ end;
+
+ ///
+ /// Sets the message status to sent.
+ ///
+ ///
+ /// This method will be marked as obsolete soon:
+ /// [Obsolete('Use the overload that takes TaskID and MessageID instead.', '30.0')]
+ ///
/// Agent task message to update status.
procedure SetStatusToSent(var AgentTaskMessage: Record "Agent Task Message")
var
diff --git a/src/System Application/App/Agent/Interaction/AgentTask.Codeunit.al b/src/System Application/App/Agent/Interaction/AgentTask.Codeunit.al
index f4ee7cd018..f5f9c2809a 100644
--- a/src/System Application/App/Agent/Interaction/AgentTask.Codeunit.al
+++ b/src/System Application/App/Agent/Interaction/AgentTask.Codeunit.al
@@ -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.
///
+ /// The ID of the agent task to set to ready.
+ procedure SetStatusToReady(AgentTaskID: BigInteger)
+ var
+ AgentTaskImpl: Codeunit "Agent Task Impl.";
+ begin
+ FeatureAccessManagement.AgentManagementAllowed(true);
+ AgentTaskImpl.SetTaskStatusToReadyIfPossible(AgentTaskID);
+ end;
+
+ ///
+ /// 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.
+ ///
+ ///
+ /// This method will be marked as obsolete soon:
+ /// [Obsolete('Use the overload that takes AgentTaskID instead.', '30.0')]
+ ///
/// The agent task to set to ready.
/// The agent task with the status set to ready.
procedure SetStatusToReady(var AgentTask: Record "Agent Task")
@@ -60,6 +77,20 @@ codeunit 4303 "Agent Task"
///
/// Checks if the task can be set to ready and started again.
///
+ /// The ID of the agent task to check.
+ /// True if agent task can be set to ready, false otherwise
+ procedure CanSetStatusToReady(AgentTaskID: BigInteger): Boolean
+ var
+ AgentTaskImpl: Codeunit "Agent Task Impl.";
+ begin
+ FeatureAccessManagement.AgentManagementAllowed(true);
+ exit(AgentTaskImpl.CanAgentTaskBeSetToReady(AgentTaskID));
+ end;
+
+ ///
+ /// 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.
+ ///
/// The agent task to check.
/// True if agent task can be set to ready, false otherwise
procedure CanSetStatusToReady(AgentTask: Record "Agent Task"): Boolean
@@ -73,6 +104,24 @@ codeunit 4303 "Agent Task"
///
/// Stops the agent task.
///
+ /// The ID of the agent task to stop.
+ /// Whether to show a confirmation dialog to the user.
+ 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;
+
+ ///
+ /// Stops the agent task.
+ ///
+ ///
+ /// This method will be marked as obsolete soon:
+ /// [Obsolete('Use the overload that takes AgentTaskID instead.', '30.0')]
+ ///
/// The agent task to stop.
/// Whether to show a confirmation dialog to the user.
procedure StopTask(var AgentTask: Record "Agent Task"; UserConfirm: Boolean)
@@ -87,6 +136,23 @@ codeunit 4303 "Agent Task"
///
/// Restarts the agent task by setting its status to ready.
///
+ /// The ID of the agent task to restart.
+ /// Whether to show a confirmation dialog to the user.
+ procedure RestartTask(AgentTaskID: BigInteger; UserConfirm: Boolean)
+ var
+ AgentTaskImpl: Codeunit "Agent Task Impl.";
+ begin
+ FeatureAccessManagement.AgentManagementAllowed(true);
+ AgentTaskImpl.RestartTask(AgentTaskID, UserConfirm);
+ end;
+
+ ///
+ /// Restarts the agent task by setting its status to ready.
+ ///
+ ///
+ /// This method will be marked as obsolete soon:
+ /// [Obsolete('Use the overload that takes AgentTaskID instead.', '30.0')]
+ ///
/// The agent task to restart.
/// Whether to show a confirmation dialog to the user.
procedure RestartTask(var AgentTask: Record "Agent Task"; UserConfirm: Boolean)
@@ -100,6 +166,20 @@ codeunit 4303 "Agent Task"
///
/// Checks if the agent task is currently running.
///
+ /// The ID of the agent task to check.
+ /// True if the task is running, false otherwise.
+ procedure IsTaskRunning(AgentTaskID: BigInteger): Boolean
+ var
+ AgentTaskImpl: Codeunit "Agent Task Impl.";
+ begin
+ FeatureAccessManagement.AgentManagementAllowed(true);
+ exit(AgentTaskImpl.IsTaskRunning(AgentTaskID));
+ end;
+
+ ///
+ /// Checks if the agent task is currently running.
+ /// The record is not retrieved again; the caller must ensure the record is up to date.
+ ///
/// The agent task to check.
/// True if the task is running, false otherwise.
procedure IsTaskRunning(var AgentTask: Record "Agent Task"): Boolean
@@ -113,6 +193,20 @@ codeunit 4303 "Agent Task"
///
/// Checks if the agent task is completed.
///
+ /// The ID of the agent task to check.
+ /// True if the task is completed, false otherwise.
+ procedure IsTaskCompleted(AgentTaskID: BigInteger): Boolean
+ var
+ AgentTaskImpl: Codeunit "Agent Task Impl.";
+ begin
+ FeatureAccessManagement.AgentManagementAllowed(true);
+ exit(AgentTaskImpl.IsTaskCompleted(AgentTaskID));
+ end;
+
+ ///
+ /// Checks if the agent task is completed.
+ /// The record is not retrieved again; the caller must ensure the record is up to date.
+ ///
/// The agent task to check.
/// True if the task is completed, false otherwise.
procedure IsTaskCompleted(var AgentTask: Record "Agent Task"): Boolean
@@ -126,6 +220,20 @@ codeunit 4303 "Agent Task"
///
/// Checks if the agent task is stopped (by user or system).
///
+ /// The ID of the agent task to check.
+ /// True if the task is stopped, false otherwise.
+ procedure IsTaskStopped(AgentTaskID: BigInteger): Boolean
+ var
+ AgentTaskImpl: Codeunit "Agent Task Impl.";
+ begin
+ FeatureAccessManagement.AgentManagementAllowed(true);
+ exit(AgentTaskImpl.IsTaskStopped(AgentTaskID));
+ end;
+
+ ///
+ /// 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.
+ ///
/// The agent task to check.
/// True if the task is stopped, false otherwise.
procedure IsTaskStopped(var AgentTask: Record "Agent Task"): Boolean
diff --git a/src/System Application/App/Agent/Interaction/AgentTaskMessageBuilder.Codeunit.al b/src/System Application/App/Agent/Interaction/AgentTaskMessageBuilder.Codeunit.al
index 477094f99a..acee063196 100644
--- a/src/System Application/App/Agent/Interaction/AgentTaskMessageBuilder.Codeunit.al
+++ b/src/System Application/App/Agent/Interaction/AgentTaskMessageBuilder.Codeunit.al
@@ -212,7 +212,7 @@ codeunit 4316 "Agent Task Message Builder"
/// This instance of the Agent Task Message Builder.
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;
diff --git a/src/System Application/App/Agent/Interaction/Internal/AgentMessageImpl.Codeunit.al b/src/System Application/App/Agent/Interaction/Internal/AgentMessageImpl.Codeunit.al
index bb7ef62fbc..bb78c726e7 100644
--- a/src/System Application/App/Agent/Interaction/Internal/AgentMessageImpl.Codeunit.al
+++ b/src/System Application/App/Agent/Interaction/Internal/AgentMessageImpl.Codeunit.al
@@ -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.";
@@ -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)
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
+ var
+ AgentTaskMessage: Record "Agent Task Message";
+ begin
+ AgentTaskMessage.Get(TaskID, MessageID);
+ exit(IsEditable(AgentTaskMessage));
end;
procedure IsEditable(var AgentTaskMessage: Record "Agent Task Message"): Boolean
@@ -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);
@@ -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
diff --git a/src/System Application/App/Agent/Interaction/Internal/AgentTaskImpl.Codeunit.al b/src/System Application/App/Agent/Interaction/Internal/AgentTaskImpl.Codeunit.al
index 8df64a5704..1447f352bf 100644
--- a/src/System Application/App/Agent/Interaction/Internal/AgentTaskImpl.Codeunit.al
+++ b/src/System Application/App/Agent/Interaction/Internal/AgentTaskImpl.Codeunit.al
@@ -15,16 +15,6 @@ codeunit 4300 "Agent Task Impl."
InherentEntitlements = X;
InherentPermissions = X;
- procedure SetMessageText(var AgentTaskMessage: Record "Agent Task Message"; MessageText: Text)
- var
- ContentOutStream: OutStream;
- begin
- Clear(AgentTaskMessage.Content);
- AgentTaskMessage.Content.CreateOutStream(ContentOutStream, GetDefaultEncoding());
- ContentOutStream.Write(MessageText);
- AgentTaskMessage.Modify(true);
- end;
-
procedure GetStepsDoneCount(var AgentTask: Record "Agent Task"): Integer
var
AgentTaskLogEntry: Record "Agent Task Log Entry";
@@ -82,29 +72,68 @@ codeunit 4300 "Agent Task Impl."
exit(AgentTaskMessage);
end;
+ local procedure SetMessageText(var AgentTaskMessage: Record "Agent Task Message"; MessageText: Text)
+ var
+ AgentTaskMessageToModify: Record "Agent Task Message";
+ ContentOutStream: OutStream;
+ begin
+ AgentTaskMessageToModify.Get(AgentTaskMessage."Task ID", AgentTaskMessage.ID);
+ Clear(AgentTaskMessageToModify.Content);
+ AgentTaskMessageToModify.Content.CreateOutStream(ContentOutStream, GetDefaultEncoding());
+ ContentOutStream.Write(MessageText);
+ end;
+
+ procedure StopTask(AgentTaskID: BigInteger; AgentTaskStatus: enum "Agent Task Status"; UserConfirm: Boolean)
+ var
+ AgentTask: Record "Agent Task";
+ begin
+ AgentTask.ID := AgentTaskID;
+ StopTask(AgentTask, AgentTaskStatus, UserConfirm);
+ end;
+
procedure StopTask(var AgentTask: Record "Agent Task"; AgentTaskStatus: enum "Agent Task Status"; UserConfirm: Boolean)
+ var
+ AgentTaskToModify: Record "Agent Task";
begin
- if ((AgentTask.Status = AgentTaskStatus) and (AgentTask."Needs Attention" = false)) then
+ AgentTaskToModify.Get(AgentTask.ID);
+ if ((AgentTaskToModify.Status = AgentTaskStatus) and (AgentTaskToModify."Needs Attention" = false)) then
exit; // Task is already stopped and does not need attention.
if UserConfirm then
if not Confirm(AreYouSureThatYouWantToStopTheTaskQst) then
exit;
- AgentTask.Status := AgentTaskStatus;
- AgentTask."Needs Attention" := false;
- AgentTask.Modify(true);
+ AgentTaskToModify.Status := AgentTaskStatus;
+ AgentTaskToModify."Needs Attention" := false;
+ AgentTaskToModify.Modify(true);
+
+ AgentTask.Status := AgentTaskToModify.Status;
+ AgentTask."Needs Attention" := AgentTaskToModify."Needs Attention";
+ end;
+
+ procedure RestartTask(AgentTaskID: BigInteger; UserConfirm: Boolean)
+ var
+ AgentTask: Record "Agent Task";
+ begin
+ AgentTask.ID := AgentTaskID;
+ RestartTask(AgentTask, UserConfirm);
end;
procedure RestartTask(var AgentTask: Record "Agent Task"; UserConfirm: Boolean)
+ var
+ AgentTaskToModify: Record "Agent Task";
begin
if UserConfirm then
if not Confirm(AreYouSureThatYouWantToRestartTheTaskQst) then
exit;
- AgentTask."Needs Attention" := false;
- AgentTask.Status := AgentTask.Status::Ready;
- AgentTask.Modify(true);
+ AgentTaskToModify.Get(AgentTask.ID);
+ AgentTaskToModify."Needs Attention" := false;
+ AgentTaskToModify.Status := AgentTaskToModify.Status::Ready;
+ AgentTaskToModify.Modify(true);
+
+ AgentTask."Needs Attention" := AgentTaskToModify."Needs Attention";
+ AgentTask.Status := AgentTaskToModify.Status;
end;
procedure TaskExists(AgentUserSecurityID: Guid; ConversationId: Text): Boolean
@@ -122,31 +151,75 @@ codeunit 4300 "Agent Task Impl."
exit(TextEncoding::UTF8);
end;
+ procedure SetTaskStatusToReadyIfPossible(AgentTaskID: BigInteger)
+ var
+ AgentTask: Record "Agent Task";
+ begin
+ AgentTask.ID := AgentTaskID;
+ SetTaskStatusToReadyIfPossible(AgentTask);
+ end;
+
procedure SetTaskStatusToReadyIfPossible(var AgentTask: Record "Agent Task")
+ var
+ AgentTaskToModify: Record "Agent Task";
begin
// Only change the status if the task is in a status where it can be started again.
// If the task is running, we should not change the state, as platform will pickup a new message automatically.
if CanAgentTaskBeSetToReady(AgentTask) then begin
- AgentTask.Status := AgentTask.Status::Ready;
- AgentTask.Modify(true);
+ AgentTaskToModify.Get(AgentTask.ID);
+ AgentTaskToModify.Status := AgentTaskToModify.Status::Ready;
+ AgentTaskToModify.Modify(true);
+ AgentTask.Status := AgentTaskToModify.Status;
end;
end;
+ procedure CanAgentTaskBeSetToReady(AgentTaskID: BigInteger): Boolean
+ var
+ AgentTask: Record "Agent Task";
+ begin
+ AgentTask.Get(AgentTaskID);
+ exit(CanAgentTaskBeSetToReady(AgentTask));
+ end;
+
procedure CanAgentTaskBeSetToReady(var AgentTask: Record "Agent Task"): Boolean
begin
exit((AgentTask.Status = AgentTask.Status::Paused) or (AgentTask.Status = AgentTask.Status::Completed));
end;
+ procedure IsTaskRunning(AgentTaskID: BigInteger): Boolean
+ var
+ AgentTask: Record "Agent Task";
+ begin
+ AgentTask.Get(AgentTaskID);
+ exit(IsTaskRunning(AgentTask));
+ end;
+
procedure IsTaskRunning(var AgentTask: Record "Agent Task"): Boolean
begin
exit(AgentTask.Status = AgentTask.Status::Running);
end;
+ procedure IsTaskCompleted(AgentTaskID: BigInteger): Boolean
+ var
+ AgentTask: Record "Agent Task";
+ begin
+ AgentTask.Get(AgentTaskID);
+ exit(IsTaskCompleted(AgentTask));
+ end;
+
procedure IsTaskCompleted(var AgentTask: Record "Agent Task"): Boolean
begin
exit(AgentTask.Status = AgentTask.Status::Completed);
end;
+ procedure IsTaskStopped(AgentTaskID: BigInteger): Boolean
+ var
+ AgentTask: Record "Agent Task";
+ begin
+ AgentTask.Get(AgentTaskID);
+ exit(IsTaskStopped(AgentTask));
+ end;
+
procedure IsTaskStopped(var AgentTask: Record "Agent Task"): Boolean
begin
exit((AgentTask.Status = AgentTask.Status::"Stopped by User") or (AgentTask.Status = AgentTask.Status::"Stopped by System"));
diff --git a/src/System Application/App/Agent/Interaction/Internal/AgentTaskList.Page.al b/src/System Application/App/Agent/Interaction/Internal/AgentTaskList.Page.al
index 8e70bce093..f72bd929de 100644
--- a/src/System Application/App/Agent/Interaction/Internal/AgentTaskList.Page.al
+++ b/src/System Application/App/Agent/Interaction/Internal/AgentTaskList.Page.al
@@ -168,7 +168,7 @@ page 4300 "Agent Task List"
var
AgentTaskImpl: Codeunit "Agent Task Impl.";
begin
- AgentTaskImpl.StopTask(Rec, Rec."Status"::"Stopped by User", true);
+ AgentTaskImpl.StopTask(Rec.ID, Rec."Status"::"Stopped by User", true);
CurrPage.Update(false);
end;
}
diff --git a/src/System Application/App/Agent/Interaction/Internal/AgentTaskMessageCard.Page.al b/src/System Application/App/Agent/Interaction/Internal/AgentTaskMessageCard.Page.al
index 4944c6a55c..4ca3ac2ef2 100644
--- a/src/System Application/App/Agent/Interaction/Internal/AgentTaskMessageCard.Page.al
+++ b/src/System Application/App/Agent/Interaction/Internal/AgentTaskMessageCard.Page.al
@@ -87,7 +87,7 @@ page 4308 "Agent Task Message Card"
var
AgentMessage: Codeunit "Agent Message";
begin
- AgentMessage.UpdateText(Rec, GlobalMessageText);
+ AgentMessage.UpdateText(Rec."Task ID", Rec.ID, GlobalMessageText);
end;
}
}
diff --git a/src/System Application/Test/Agent/src/SDK/AgentMessageTest.Codeunit.al b/src/System Application/Test/Agent/src/SDK/AgentMessageTest.Codeunit.al
index 77955455b4..76fb6133db 100644
--- a/src/System Application/Test/Agent/src/SDK/AgentMessageTest.Codeunit.al
+++ b/src/System Application/Test/Agent/src/SDK/AgentMessageTest.Codeunit.al
@@ -193,6 +193,62 @@ codeunit 133963 "Agent Message Test"
Assert.IsTrue(TempAgentTaskFile.IsEmpty(), 'No attachments should exist');
end;
+ [Test]
+ procedure UpdateTextDoesNotOverwriteUnrelatedFields()
+ var
+ AgentRecord: Record Agent;
+ AgentTaskRecord: Record "Agent Task";
+ AgentTaskMessageRecord: Record "Agent Task Message";
+ AgentTaskBuilder: Codeunit "Agent Task Builder";
+ Any: Codeunit Any;
+ AgentUserId: Guid;
+ OriginalMessageText: Text;
+ UpdatedMessageText: Text;
+ OriginalFrom: Text[250];
+ ExternalIdTok: Label 'MSG-TEST-005', Locked = true;
+ begin
+ Initialize();
+
+ // [SCENARIO] UpdateText with var record should only modify Content even when the caller's record has dirty field values
+
+ // [GIVEN] A test agent with a task and message that has its status set to Sent
+ OriginalFrom := 'Test User';
+ AgentUserId := LibraryTestAgent.GetOrCreateDefaultAgent(
+ AgentRecord,
+ CopyStr(Any.AlphanumericText(MaxStrLen(AgentRecord."User Name")), 1, MaxStrLen(AgentRecord."User Name")),
+ CopyStr(Any.AlphanumericText(80), 1, 80),
+ CopyStr(Any.AlphanumericText(2048), 1, 2048));
+
+ OriginalMessageText := Any.AlphanumericText(2048);
+
+ AgentTaskBuilder
+ .Initialize(AgentUserId, 'Update Text Test Task')
+ .SetExternalId(ExternalIdTok)
+ .AddTaskMessage(OriginalFrom, OriginalMessageText);
+
+ AgentTaskRecord := AgentTaskBuilder.Create(false, false);
+ AgentTaskMessageRecord := AgentTaskBuilder.GetAgentTaskMessageCreated();
+
+ AgentMessage.SetStatusToSent(AgentTaskMessageRecord."Task ID", AgentTaskMessageRecord.ID);
+
+ // Re-read the record to get the committed state
+ AgentTaskMessageRecord.Get(AgentTaskMessageRecord."Task ID", AgentTaskMessageRecord.ID);
+
+ // Modify a field on the local record variable without saving to DB
+ AgentTaskMessageRecord.From := 'Dirty Value';
+
+ // [WHEN] UpdateText is called with the dirty record via the old var-record overload
+ UpdatedMessageText := Any.AlphanumericText(2048);
+#pragma warning disable AL0432
+ AgentMessage.UpdateText(AgentTaskMessageRecord, UpdatedMessageText);
+#pragma warning restore AL0432
+
+ // [THEN] Only the Content should be updated; the dirty From value should not be persisted
+ AgentTaskMessageRecord.Get(AgentTaskMessageRecord."Task ID", AgentTaskMessageRecord.ID);
+ Assert.AreEqual(UpdatedMessageText, AgentMessage.GetText(AgentTaskMessageRecord), 'Message text should be updated');
+ Assert.AreEqual(OriginalFrom, AgentTaskMessageRecord.From, 'From field should not be overwritten by dirty record passed to UpdateText');
+ end;
+
#endregion
#region Agent Task Message Builder Tests
diff --git a/src/System Application/Test/Agent/src/SDK/AgentTaskManagementTest.Codeunit.al b/src/System Application/Test/Agent/src/SDK/AgentTaskManagementTest.Codeunit.al
index b04c6bb04f..9ba308510d 100644
--- a/src/System Application/Test/Agent/src/SDK/AgentTaskManagementTest.Codeunit.al
+++ b/src/System Application/Test/Agent/src/SDK/AgentTaskManagementTest.Codeunit.al
@@ -95,7 +95,7 @@ codeunit 133962 "Agent Task Management Test"
Assert.IsTrue(AgentTask.CanSetStatusToReady(AgentTaskRecord), 'Task should be able to be set to ready');
// [WHEN] Setting the task status to ready
- AgentTask.SetStatusToReady(AgentTaskRecord);
+ AgentTask.SetStatusToReady(AgentTaskRecord.ID);
// [THEN] The task should be ready for processing
AgentTaskRecord.Get(AgentTaskRecord.Id);
@@ -169,7 +169,7 @@ codeunit 133962 "Agent Task Management Test"
AgentTaskRecord := AgentTaskBuilder.Create(true, false); // Allow for tasks without message.
// [WHEN] Stopping the task without user confirmation
- AgentTask.StopTask(AgentTaskRecord, false);
+ AgentTask.StopTask(AgentTaskRecord.ID, false);
// [THEN] The task should be stopped
AgentTaskRecord.Get(AgentTaskRecord.Id);
@@ -204,7 +204,7 @@ codeunit 133962 "Agent Task Management Test"
AgentTaskRecord := AgentTaskBuilder.Create(true, false); // Allow for tasks without message.
// [WHEN] The task is stopped
- AgentTask.StopTask(AgentTaskRecord, false);
+ AgentTask.StopTask(AgentTaskRecord.ID, false);
// [THEN] The task should be marked as stopped
AgentTaskRecord.Get(AgentTaskRecord.Id);
@@ -325,12 +325,12 @@ codeunit 133962 "Agent Task Management Test"
AgentTaskRecord := AgentTaskBuilder.Create(true, false); // Allow for tasks without message.
// [GIVEN] The task is stopped
- AgentTask.StopTask(AgentTaskRecord, false);
+ AgentTask.StopTask(AgentTaskRecord.ID, false);
AgentTaskRecord.Get(AgentTaskRecord.Id);
Assert.IsTrue(AgentTask.IsTaskStopped(AgentTaskRecord), 'Task should be stopped initially');
// [WHEN] Restarting the task without user confirmation
- AgentTask.RestartTask(AgentTaskRecord, false);
+ AgentTask.RestartTask(AgentTaskRecord.ID, false);
// [THEN] The task should no longer be stopped
AgentTaskRecord.Get(AgentTaskRecord.Id);
@@ -363,10 +363,10 @@ codeunit 133962 "Agent Task Management Test"
.SetExternalId(ExternalIdTok);
AgentTaskRecord := AgentTaskBuilder.Create(true, false); // Allow for tasks without message.
- AgentTask.StopTask(AgentTaskRecord, false);
+ AgentTask.StopTask(AgentTaskRecord.ID, false);
// [WHEN] Restarting the task
- AgentTask.RestartTask(AgentTaskRecord, false);
+ AgentTask.RestartTask(AgentTaskRecord.ID, false);
// [THEN] The task should be ready to process
AgentTaskRecord.Get(AgentTaskRecord.Id);
@@ -511,20 +511,20 @@ codeunit 133962 "Agent Task Management Test"
// [WHEN] Stopping and restarting the task multiple times
// First cycle
- AgentTask.StopTask(AgentTaskRecord, false);
+ AgentTask.StopTask(AgentTaskRecord.ID, false);
AgentTaskRecord.Get(AgentTaskRecord.Id);
Assert.IsTrue(AgentTask.IsTaskStopped(AgentTaskRecord), 'Task should be stopped after first stop');
- AgentTask.RestartTask(AgentTaskRecord, false);
+ AgentTask.RestartTask(AgentTaskRecord.ID, false);
AgentTaskRecord.Get(AgentTaskRecord.Id);
Assert.IsFalse(AgentTask.IsTaskStopped(AgentTaskRecord), 'Task should not be stopped after first restart');
// Second cycle
- AgentTask.StopTask(AgentTaskRecord, false);
+ AgentTask.StopTask(AgentTaskRecord.ID, false);
AgentTaskRecord.Get(AgentTaskRecord.Id);
Assert.IsTrue(AgentTask.IsTaskStopped(AgentTaskRecord), 'Task should be stopped after second stop');
- AgentTask.RestartTask(AgentTaskRecord, false);
+ AgentTask.RestartTask(AgentTaskRecord.ID, false);
AgentTaskRecord.Get(AgentTaskRecord.Id);
Assert.IsFalse(AgentTask.IsTaskStopped(AgentTaskRecord), 'Task should not be stopped after second restart');
@@ -569,10 +569,10 @@ codeunit 133962 "Agent Task Management Test"
AgentTaskRecord3 := AgentTaskBuilder.Create(true, false); // Allow for tasks without message.
// [WHEN] Managing tasks with different operations
- AgentTask.StopTask(AgentTaskRecord1, false);
+ AgentTask.StopTask(AgentTaskRecord1.ID, false);
- AgentTask.StopTask(AgentTaskRecord2, false);
- AgentTask.RestartTask(AgentTaskRecord2, false);
+ AgentTask.StopTask(AgentTaskRecord2.ID, false);
+ AgentTask.RestartTask(AgentTaskRecord2.ID, false);
// [THEN] Each task should have the correct state
AgentTaskRecord1.Get(AgentTaskRecord1.Id);
@@ -614,8 +614,8 @@ codeunit 133962 "Agent Task Management Test"
AgentTaskRecord := AgentTaskBuilder.Create(true, false); // Allow for tasks without message.
// [GIVEN] The task is stopped and restarted
- AgentTask.StopTask(AgentTaskRecord, false);
- AgentTask.RestartTask(AgentTaskRecord, false);
+ AgentTask.StopTask(AgentTaskRecord.ID, false);
+ AgentTask.RestartTask(AgentTaskRecord.ID, false);
// [WHEN] Retrieving the task by external ID
RetrievedTask := AgentTask.GetTaskByExternalId(AgentUserId, ExternalIdTok);