{"title":"Page.CancelBackgroundTask(Integer) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/page/page-cancelbackgroundtask-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/page/page-cancelbackgroundtask-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/page/page-cancelbackgroundtask-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":"Attempt to cancel a page background task.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"Page.CancelBackgroundTask(Integer) Method","slug":"pagecancelbackgroundtaskinteger-method","at":0,"chars":1422},{"level":2,"title":"Syntax","slug":"syntax","at":146,"chars":73},{"level":2,"title":"Parameters","slug":"parameters","at":219,"chars":269},{"level":2,"title":"Return Value","slug":"return-value","at":488,"chars":146},{"level":2,"title":"Example","slug":"example","at":634,"chars":583},{"level":2,"title":"Related information","slug":"related-information","at":1217,"chars":205}],"text":"# Page.CancelBackgroundTask(Integer) Method\n> Version: _Available or changed with runtime version 4.0._\nAttempt to cancel a page background task.\n## Syntax\n```al\n[Ok := ]  Page.CancelBackgroundTask(TaskId: Integer)\n```\n## Parameters\nPage\nType: page-data-type\nAn instance of the page-data-type data type.\nTaskId\nType: ../integer/integer-data-type\nSpecifies the ID of the page background task to cancel. The ID is assigned to the task when it is queued by the EnqueueBackgroundTask method.\n## Return Value\n*[Optional] Ok*\nType: ../boolean/boolean-data-type\ntrue if the page background task was marked for cancellation; otherwise false.\n## Example\nThe following example uses the CancelBackgroundTask method to cancel an existing page background task, based on its task ID.\n```al\nvar​\n  WaitTaskId: Integer;​\n​\ntrigger OnAfterGetRecord()​\nvar​\n  TaskParameters: Dictionary of [Text, Text];​\nbegin​\n  if (WaitTaskId > 0) then​\n    Currpage.CancelBackgroundTask(WaitTaskId);​\n    TaskParameters.Add('Wait', '1000');\n    CurrPage.EnqueueBackgroundTask(WaitTaskId, 50100, TaskParameters, 1000, PageBackgroundTaskErrorLevel::Warning);\nend;\n```\nCurrPage is a system-defined variable. See ../../devenv-system-defined-variables.\n## Related information\n../../devenv-page-background-tasks\npage-data-type\n../../devenv-system-defined-variables\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}