{"title":"Isolated Events in AL","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/devenv-events-isolated/","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/devenv-events-isolated, 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/devenv-events-isolated","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":"Describes how isolated events work in Business Central.","date":"2021-11-11","meta":{"topic":"article"},"outline":[{"level":1,"title":"Isolated Events in AL","slug":"isolated-events-in-al","at":0,"chars":4357},{"level":2,"title":"How isolated events work","slug":"how-isolated-events-work","at":422,"chars":1707},{"level":3,"title":"Rollback","slug":"rollback","at":1371,"chars":391},{"level":3,"title":"Extension installation and upgrade","slug":"extension-installation-and-upgrade","at":1762,"chars":367},{"level":2,"title":"How to define an isolated event","slug":"how-to-define-an-isolated-event","at":2129,"chars":431},{"level":2,"title":"Example","slug":"example","at":2560,"chars":1618},{"level":2,"title":"Related information","slug":"related-information","at":4178,"chars":179}],"text":"# Isolated Events in AL\nYou can define a business, integration, or internal event to be an isolated event. An isolated event ensures the event publisher continues its code execution after calling an event. If an event subscriber's code causes an error, its transaction and associated table changes will be rolled back. The execution continues to the next event subscriber, or it will be handed back to the event's caller.\n## How isolated events work\nIsolated events are implemented by separating each event subscriber into its own transaction. The transaction is created before invoking an event subscriber, then committed afterwards. The following diagram illustrates the flow.\nWhen an event is raised, the platform gets the first event subscriber. When the event is isolated, an isolated transaction starts, then the event subscriber is invoked. If an error occurs, the transaction is rolled back, and the flow is repeated for the next event subscriber. Otherwise, the transaction is committed and the flow is repeated for the next event subscriber.\n> NOTE\n> Read-only transactions are allowed to call isolated events directly, but write transactions should explicitly be committed before invoking an isolated event. Otherwise, the isolated event will be invoked like an normal event, that is, errors inside an event subscriber will cause the entire operation to fail.\n### Rollback\nOnly changes done via Modify/Delete/Insert calls on records of type `TableType: Normal` will be automatically rolled back. Other state changes, like HTTP calls, variable alterations, changes to single instance codeunit's members, won't be rolled back.\nFor example, if an integer variable that's passed by VAR is modified by a failing event subscriber, its changes will persist.\n### Extension installation and upgrade\nWhen the operation is installing, uninstalling, or upgrading extensions, isolated events aren't run isolated. The events run normally instead.\nThe reason for this behavior is that these operations require that all operations within them are done in one transaction. So explicit Commit calls can't be made during the operations.\n## How to define an isolated event\nThe attributes/devenv-businessevent-attribute, attributes/devenv-integrationevent-attribute, and attributes/devenv-internalevent-attribute attributes include the Isolated boolean argument, for example:\n```al\n[InternalEvent(IncludeSender: Boolean, Isolated: Boolean)]\n```\nTo define an isolated event, set the Isolated argument, which is to true, for example:\n```al\n[InternalEvent(true, true)]\n```\n## Example\n```al\ncodeunit 50145 IsolatedEventsSample\n{\n    trigger OnRun()\n    var\n        Counter: Integer;\n        cust : Record Customer;\n    begin\n        // Precondition: Customer table isn't empty.\n        if (cust.IsEmpty) then\n            Error('Customer table is empty.');\n\n        MyIsolatedEvent(Counter);\n\n        // Code only reaches this point because the above event is isolated and error thrown in FailingEventSubscriber is caught.\n        if (Counter <> 2) then\n            Error('Both event subscribers should have incremented the counter.');\n\n        // Post-condition: Customer table hasn't been truncated.\n        if (cust.IsEmpty) then\n            Error('Customer table was truncated, failing event subscriber was not rolled back.');\n    end;\n\n    [InternalEvent(false, true)]\n    local procedure MyIsolatedEvent(var Counter: Integer)\n    begin\n    end;\n\n    [EventSubscriber(ObjectType::Codeunit, Codeunit::IsolatedEventsSample, 'MyIsolatedEvent', '', false, false)]\n    local procedure FailingEventSubscriber(var Counter: Integer)\n    var\n        cust: Record Customer;\n    begin\n        Counter += 1; // Change will persist even after throwing. Only database changes will be rolled back.\n\n        cust.DeleteAll(); // Database changes will be rolled back upon error.\n\n        Error('Fail!');\n\n        // Code below won't be reached!\n        Counter += 1;\n    end;\n\n    [EventSubscriber(ObjectType::Codeunit, Codeunit::IsolatedEventsSample, 'MyIsolatedEvent', '', false, false)]\n    local procedure IncreasingEventSubscriber(var Counter: Integer)\n    begin\n        Counter += 1;\n    end;\n}\n```\n## Related information\ndevenv-publishing-events\ndevenv-raising-events\ndevenv-subscribing-to-events\nDeveloping Extensions Using the New Development Environment<devenv-dev-overview>"}