{"title":"Event Example","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/devenv-events-example/","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-example, 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-example","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":"This article shows a simple example of how to use events in Business Central.","date":"2021-04-01","meta":{"topic":"article"},"outline":[{"level":2,"title":"Related information","slug":"related-information","at":2349,"chars":139}],"text":"This article includes a simple code example to explain how to use Business Central events. The example uses an event to verify a customer's address. When a user changes the address of a customer on the page 21 Customer Card, an event is used to check that the address doesn't include a plus sign (+). If it does, a message is displayed in the client. In this example, you'll add code that:\n Publishes an event that is raised when the Address field on Customer Card is changed.\n Raises the event from the Customer Card page\n Subscribes to the event to check the address value and return a message to the user if it contains a plus sign.\n```al\n// The following code creates codeunit that publishes the `OnAddressLineChanged` event.\n\ncodeunit 50100 MyPublishers\n{\n    [IntegrationEvent(false, false)]\n    procedure OnAddressLineChanged(line: Text[100])\n    begin\n    end;\n}\n\n// The following code extends the Customer Card page to raise the `OnAddressLineChanged` event\n// when the Address field is changed.\npageextension 50100 MyCustomerExt extends \"Customer Card\"\n{\n    layout\n    {\n        modify(Address)\n        {\n            trigger OnBeforeValidate();\n            var\n                Publisher: Codeunit MyPublishers;\n            begin\n                Publisher.OnAddressLineChanged(Rec.Address);\n            end;\n        }\n    }\n}\n\n// The following code creates an event subscriber codeunit.\n// It declares the `CheckAddressLine` event subscriber that listens for OnAddressLineChanged event.\n// The event subscriber displays a message in the client when '+' is used in the **Address** field.\n\ncodeunit 50101 MySubscribers\n{\n    //Set the event subscribers to bind automatically to the event\n    EventSubscriberInstance = StaticAutomatic;\n\n    [EventSubscriber(ObjectType::Codeunit, Codeunit::\"MyPublishers\", 'OnAddressLineChanged', '', true, true)]\n    procedure CheckAddressLine(line: Text[100])\n    begin\n        if (STRPOS(line, '+') > 0) then begin\n            MESSAGE('Can''t use a plus sign (+) in the address [' + line + ']');\n        end;\n    end;\n}\n```\n> TIP\n> This example binds the event subscriber automatically to the event. You can also bind the event subscriber manually, by setting the EventSubscriberInstance property. For more information, including an example, see properties/devenv-eventsubscriberinstance-property#example.\n## Related information\ndevenv-publishing-events\ndevenv-raising-events\ndevenv-subscribing-to-events\nEvents Dynamics 365<devenv-events-in-al>"}