@@ -52,6 +52,19 @@ codeunit 4300 "Agent Task Impl."
52
52
Page . Run( Page ::"Agent Task Step List", AgentTaskStep) ;
53
53
end ;
54
54
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
+
55
68
procedure CreateTaskMessage( From: Text [250 ]; MessageText: Text ; var CurrentAgentTask: Record "Agent Task")
56
69
begin
57
70
CreateTaskMessage( From, MessageText, ' ' , CurrentAgentTask) ;
@@ -82,13 +95,7 @@ codeunit 4300 "Agent Task Impl."
82
95
AgentTaskMessage. Insert() ;
83
96
84
97
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) ;
92
99
end ;
93
100
94
101
procedure CreateUserInterventionTaskStep( UserInterventionRequestStep: Record "Agent Task Step")
@@ -170,6 +177,16 @@ codeunit 4300 "Agent Task Impl."
170
177
exit ( TextEncoding ::UTF8) ;
171
178
end ;
172
179
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
+
173
190
[EventSubscriber( ObjectType ::Codeunit , Codeunit ::"System Action Triggers", GetAgentTaskMessagePageId, ' ' , true, true) ]
174
191
local procedure OnGetAgentTaskMessagePageId( var PageId: Integer )
175
192
begin
0 commit comments