
Announcements
local procedure CreateJobQueueEntry(SessionId: Guid; ScheduledFor: DateTime): Guid
var
l_JobQueueEntry: Record "Job Queue Entry";
l_JobQueueEntryId: Guid;
begin
l_JobQueueEntry.Init();
l_JobQueueEntry.ID := CreateGuid();
l_JobQueueEntry."Object Type to Run" := l_JobQueueEntry."Object Type to Run"::Codeunit;
l_JobQueueEntry."Object ID to Run" := Codeunit::"BHLF-ConfigPkgImportJQHandler";
l_JobQueueEntry."Parameter String" := CopyStr(Format(SessionId), 1, MaxStrLen(l_JobQueueEntry."Parameter String"));
l_JobQueueEntry.Description := CopyStr('Config Package Import - ' + Format(SessionId), 1, MaxStrLen(l_JobQueueEntry.Description));
l_JobQueueEntry."Earliest Start Date/Time" := ScheduledFor;
l_JobQueueEntry."Expiration Date/Time" := ScheduledFor + 1;
l_JobQueueEntry."Maximum No. of Attempts to Run" := 3;
l_JobQueueEntry."Rerun Delay (sec.)" := 60;
l_JobQueueEntry."Run in User Session" := false;
l_JobQueueEntry."Job Queue Category Code" := '';
l_JobQueueEntry."User ID" := CopyStr(UserId, 1, MaxStrLen(l_JobQueueEntry."User ID"));
l_JobQueueEntry.Status := l_JobQueueEntry.Status::"On Hold"; // Explicitly set initial status
l_JobQueueEntry.Insert(true);l_JobQueueEntryId := l_JobQueueEntry.ID;Commit();l_JobQueueEntry.Get(l_JobQueueEntryId);
.
if TaskScheduler.CanCreateTask() then
l_JobQueueEntry.SetStatus(l_JobQueueEntry.Status::Ready);exit(l_JobQueueEntryId);
end;