Adds a task to run a codeunit at a specific time.
[Task =: ]CREATETASK(CodeunitId, FailureCodeunitId[, IsReady][, Company][, NotBefore][, RecordID])
Specifies the ID of the codeunit to run.
Specifies the ID of the codeunit to run if the task fails. If you do not want to provide a failure codeunit, then use 0.
Sets the task to the ready state. A task cannot run unless it is ready.
Specifies the company to run the task for. If you do not specify a company, the task will run in the user’s current company.
Specifies the date and time that you want to run the task. When the task actually runs will depend on whether other tasks are running at the same time. The task will run the first opportunity on or after the date and time that you specify.
Specifies the recordID of the record that you want to run the task on.
Property Value/Return Value
The unique identifier that is assigned to the task.
Scheduled tasks are recorded in table 2000000175 Scheduled Task. For more information about tasks and task scheduler, see managing tasks Task Scheduler.
The following example schedules a task to run the Job Queue Dispatcher and uses codeunit Job Queue Error Handler as the failure codeunit. The code requires that you create the following C/AL variable.
|JobQueueEntry||Record||Job Queue Entry|
TASKSCHEDULER.CREATETASK(CODEUNIT::"Job Queue Dispatcher", CODEUNIT::"Job Queue Error Handler", TRUE, COMPANYNAME, CURRENTDATETIME + 1000 + RANDOM(3000), JobQueueEntry.RECORDID);
To see this code in use, you can look at the C/AL code in codeunit 448 Job Queue Dispatcher in the CRONUS International Ltd. demonstration database.