{"title":"TaskScheduler.CreateTask(Integer, Integer, Boolean, Text, DateTime, RecordId, Duration) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/taskscheduler/taskscheduler-createtask-integer-integer-boolean-string-datetime-recordid-duration-method/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/taskscheduler/taskscheduler-createtask-integer-integer-boolean-string-datetime-recordid-duration-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/taskscheduler/taskscheduler-createtask-integer-integer-boolean-string-datetime-recordid-duration-method","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Adds a task to be run by the task scheduler.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"TaskScheduler.CreateTask(Integer, Integer, Boolean, Text, DateTime, RecordId, Duration) Method","slug":"taskschedulercreatetaskinteger-integer-boolean-text-datetime-recordid-duration-method","at":0,"chars":2647},{"level":2,"title":"Syntax","slug":"syntax","at":319,"chars":199},{"level":2,"title":"Parameters","slug":"parameters","at":518,"chars":1230},{"level":2,"title":"Return Value","slug":"return-value","at":1748,"chars":63},{"level":2,"title":"Remarks","slug":"remarks","at":1811,"chars":334},{"level":2,"title":"Related information","slug":"related-information","at":2145,"chars":502}],"text":"# TaskScheduler.CreateTask(Integer, Integer, Boolean, Text, DateTime, RecordId, Duration) Method\n> Version: _Available or changed with runtime version 7.0._\nAdds a task to be run by the task scheduler. The task is ensured to not run before the specified time. This method also allows you to set a timeout for the task.\n## Syntax\n```al\n[Task := ]  TaskScheduler.CreateTask(CodeunitId: Integer, FailureCodeunitId: Integer, IsReady: Boolean, Company: Text, NotBefore: DateTime, RecordID: RecordId, Timeout: Duration)\n```\n## Parameters\nCodeunitId\nType: ../integer/integer-data-type\nSpecifies the ID of the codeunit to run.\nFailureCodeunitId\nType: ../integer/integer-data-type\nSpecifies the ID of the codeunit to run if the task fails. If you do not want to provide a failure codeunit, then use 0.\nIsReady\nType: ../boolean/boolean-data-type\nSets the task to the ready state. A task cannot run unless it is ready.\nCompany\nType: ../text/text-data-type\nSpecifies the company to run the task for. If you do not specify a company, the task will run in the user's current company.\nNotBefore\nType: ../datetime/datetime-data-type\nSpecifies 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.\nRecordID\nType: ../recordid/recordid-data-type\nSpecifies the recordID of the record that you want to run the task on.\nTimeout\nType: ../duration/duration-data-type\nSpecifies the timeout of the created session. If not specified a default timeout will be used; for OnPrem, the default timeout is set on the server, for SaaS the current default timeout is 12 hours, and may change in the future.\n## Return Value\n*[Optional] Task*\nType: ../guid/guid-data-type\n## Remarks\nThis version of the TaskScheduler.CreateTask method has the same semantics as the version without a timeout parameter. For more information and usage examples, see CreateTask(Integer, Integer [, Boolean] [, Text] [, DateTime] [, RecordId])<taskscheduler-createtask-integer-integer-boolean-string-datetime-recordid-method>.\n## Related information\nCreateTask(Integer, Integer [, Boolean] [, Text] [, DateTime] [, RecordId])<taskscheduler-createtask-integer-integer-boolean-string-datetime-recordid-method>\ntaskscheduler-data-type\nUsing the Task Scheduler<../../devenv-task-scheduler>\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>\nConfiguring Business Central Server - Default Task Scheduler Session Timeout<../../../administration/server-instance-settings#schedule-server-tasks>"}