TaskScheduler.CreateTask(Integer, Integer [, Boolean] [, String] [, DateTime] [, RecordId]) Method

Version: Available or changed with runtime version 1.0.

Adds a task to ensure that a codeunit is not run before the specified time.


[Task := ]  TaskScheduler.CreateTask(CodeunitId: Integer, FailureCodeunitId: Integer [, IsReady: Boolean] [, Company: String] [, NotBefore: DateTime] [, RecordID: RecordId])


 Type: Integer
Specifies the ID of the codeunit to run.

 Type: Integer
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.

[Optional] IsReady
 Type: Boolean
Sets the task to the ready state. A task cannot run unless it is ready.

[Optional] Company
 Type: String
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.

[Optional] NotBefore
 Type: DateTime
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.

[Optional] RecordID
 Type: RecordId
Specifies the recordID of the record that you want to run the task on.

Return Value

[Optional] Task
 Type: Guid


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.

    JobQueueEntry: Record "Job Queue Entry";
    TaskScheduler.CreateTASK(CodeUnit::"Job Queue Dispatcher", CodeUnit::"Job Queue Error Handler", True, CompanyName, CurrentDateTime + 1000 + Random(3000), JobQueueEntry.RecordID);  

See Also

TaskScheduler Data Type
Getting Started with AL
Developing Extensions