Dear Business Central / AL developer experts,
I am trying to get the TaskScheduler to work. I can schedule a task, it is visible in the "Scheduled Tasks" table. At the scheduled time, a row in the "Session Events" table appears. But the task does not do it's usual work. What can be the reason for this?
I wrote a test CodeUnit, if I run it by hand it writes a message to a custom log table. If I schedule it, the message does not get written.
Please see the code below.
Also added: a zip of the AL test project (with the MS apps removed to make it uploadable).
===========================
codeunit 60001 TaskSchedulerTest { //This is the Task to perform. trigger OnRun() var Log: Record MessageLog; begin Log.Log(3, 'The test CodeUnit 60001 has run!'); end; //This should schedule the Task, a chosen number of minutes after NOW. procedure ScheduleMe() var MinutesAfterNow: Integer; TargetCompany: Text; NotBefore: DateTime; TaskGuid: Guid; begin //Configure the scheduling MinutesAfterNow := 20; TargetCompany := 'Entocare CV'; //Change it //Schedule this CodeUnit NotBefore := CreateDateTime(Today(), Time()) MinutesAfterNow * 60 * 1000; if not TaskScheduler.CanCreateTask() then Error('CanCreateTask is false.'); TaskGuid := TaskScheduler.CreateTask(70001, 0, true, TargetCompany, NotBefore); Message('Scheduled: ' TaskGuid); end; }