Skip to content

Commit 542ec09

Browse files
Bugs/561761 create task without message system app (#2816)
#### Summary Add ability to create tasks without messages #### Work Item(s) > Fixes [AB#561761](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/561761)
1 parent 4fb9276 commit 542ec09

File tree

5 files changed

+39
-10
lines changed

5 files changed

+39
-10
lines changed

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

+15
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,19 @@ codeunit 4303 "Agent Task"
3838
begin
3939
AgentTaskImpl.CreateTaskMessage(From, MessageText, ExternalMessageId, CurrentAgentTask);
4040
end;
41+
42+
/// <summary>
43+
/// Create a new task for the given agent user. No message is added to the task.
44+
/// </summary>
45+
/// <param name="AgentSecurityID">The security ID of the agent to create the task for.</param>
46+
/// <param name="TaskTitle">The title of the task.</param>
47+
/// <param name="ExternalId">The external ID of the task. This field is used to connect to external systems, like Message ID for emails.</param>
48+
/// <param name="NewAgentTask">The new agent task record that was created.</param>
49+
[Scope('OnPrem')]
50+
procedure CreateTaskWithoutMessage(AgentSecurityID: Guid; TaskTitle: Text[150]; ExternalId: Text[2048]; var NewAgentTask: Record "Agent Task")
51+
var
52+
AgentTaskImpl: Codeunit "Agent Task Impl.";
53+
begin
54+
AgentTaskImpl.CreateTask(AgentSecurityID, TaskTitle, ExternalId, NewAgentTask);
55+
end;
4156
}

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

+24-7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ codeunit 4300 "Agent Task Impl."
5252
Page.Run(Page::"Agent Task Step List", AgentTaskStep);
5353
end;
5454

55+
procedure CreateTask(AgentSecurityID: Guid; TaskTitle: Text[150]; ExternalId: Text[2048]; var NewAgentTask: Record "Agent Task")
56+
begin
57+
Clear(NewAgentTask);
58+
NewAgentTask."Agent User Security ID" := AgentSecurityID;
59+
NewAgentTask.Title := TaskTitle;
60+
NewAgentTask."Created By" := UserSecurityId();
61+
NewAgentTask."Needs Attention" := false;
62+
NewAgentTask.Status := NewAgentTask.Status::Paused;
63+
NewAgentTask."External ID" := ExternalId;
64+
NewAgentTask.Insert();
65+
StartTaskIfPossible(NewAgentTask);
66+
end;
67+
5568
procedure CreateTaskMessage(From: Text[250]; MessageText: Text; var CurrentAgentTask: Record "Agent Task")
5669
begin
5770
CreateTaskMessage(From, MessageText, '', CurrentAgentTask);
@@ -82,13 +95,7 @@ codeunit 4300 "Agent Task Impl."
8295
AgentTaskMessage.Insert();
8396

8497
SetMessageText(AgentTaskMessage, MessageText);
85-
86-
// Only change the status if the task is in a status where it can be started again.
87-
// If the task is running, we should not change the state, as platform will pickup a new message automatically.
88-
if ((AgentTask.Status = AgentTask.Status::Paused) or (AgentTask.Status = AgentTask.Status::Completed)) then begin
89-
AgentTask.Status := AgentTask.Status::Ready;
90-
AgentTask.Modify(true);
91-
end;
98+
StartTaskIfPossible(AgentTask);
9299
end;
93100

94101
procedure CreateUserInterventionTaskStep(UserInterventionRequestStep: Record "Agent Task Step")
@@ -170,6 +177,16 @@ codeunit 4300 "Agent Task Impl."
170177
exit(TextEncoding::UTF8);
171178
end;
172179

180+
local procedure StartTaskIfPossible(var AgentTask: Record "Agent Task")
181+
begin
182+
// Only change the status if the task is in a status where it can be started again.
183+
// If the task is running, we should not change the state, as platform will pickup a new message automatically.
184+
if ((AgentTask.Status = AgentTask.Status::Paused) or (AgentTask.Status = AgentTask.Status::Completed)) then begin
185+
AgentTask.Status := AgentTask.Status::Ready;
186+
AgentTask.Modify(true);
187+
end;
188+
end;
189+
173190
[EventSubscriber(ObjectType::Codeunit, Codeunit::"System Action Triggers", GetAgentTaskMessagePageId, '', true, true)]
174191
local procedure OnGetAgentTaskMessagePageId(var PageId: Integer)
175192
begin

src/System Application/App/Agent/Interaction/AgentTaskList.Page.al

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ page 4300 "Agent Task List"
99
{
1010
PageType = List;
1111
ApplicationArea = All;
12-
UsageCategory = Administration;
1312
SourceTable = "Agent Task";
1413
Caption = 'Agent Tasks';
1514
InsertAllowed = false;

src/System Application/App/Agent/Interaction/AgentTaskMessageList.Page.al

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ page 4301 "Agent Task Message List"
1010
PageType = List;
1111
ApplicationArea = All;
1212
Caption = 'Agent Task Messages';
13-
UsageCategory = Administration;
1413
SourceTable = "Agent Task Message";
1514
CardPageId = "Agent Task Message Card";
1615
InsertAllowed = false;

src/System Application/App/Agent/Interaction/AgentTaskStepList.Page.al

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ page 4303 "Agent Task Step List"
99
{
1010
PageType = List;
1111
ApplicationArea = All;
12-
UsageCategory = Administration;
1312
SourceTable = "Agent Task Step";
1413
Caption = 'Agent Task Steps';
1514
InsertAllowed = false;

0 commit comments

Comments
 (0)