CreateTask Method

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

Syntax

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

Parameters

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

FailureCodeunitId
 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.

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

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.

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.

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

Return Value

Task
 Type: Guid

Remarks

Scheduled tasks are recorded in table 2000000175 Scheduled Task. For more information about tasks and task scheduler, see managing tasks Task Scheduler.

Example

The following example schedules a task to run the Job Queue Dispatcher and uses codeunit Job Queue Error Handler as the failure codeunit.

var
    JobQueueEntry: Record "Job Queue Entry";
begin
    TASKSCHEDULER.CREATETASK(CODEUNIT::"Job Queue Dispatcher", CODEUNIT::"Job Queue Error Handler", TRUE, COMPANYNAME, CURRENTDATETIME + 1000 + RANDOM(3000), JobQueueEntry.RECORDID);  
end;

See Also

TaskScheduler Data Type
Getting Started with AL
Developing Extensions