{"title":"EventSubscriber attribute","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/attributes/devenv-eventsubscriber-attribute/","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/attributes/devenv-eventsubscriber-attribute, 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/attributes/devenv-eventsubscriber-attribute","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":"Specifies the event to which the method subscribes.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":2,"title":"Applies to","slug":"applies-to","at":112,"chars":95},{"level":2,"title":"Syntax","slug":"syntax","at":207,"chars":1692},{"level":3,"title":"Arguments","slug":"arguments","at":389,"chars":1510},{"level":2,"title":"Remarks","slug":"remarks","at":1899,"chars":1127},{"level":2,"title":"Integration event example","slug":"integration-event-example","at":3026,"chars":595},{"level":2,"title":"Table trigger event example","slug":"table-trigger-event-example","at":3621,"chars":663},{"level":2,"title":"Related information","slug":"related-information","at":4284,"chars":200}],"text":"> Version: _Available or changed with runtime version 1.0._\nSpecifies the event to which the method subscribes.\n## Applies to\n Method\n> NOTE\n> The EventSubscriber attribute can only be set inside codeunits.\n## Syntax\n```al\n[EventSubscriber(ObjectType: ObjectType, ObjectId: Integer, EventName: Text, ElementName: Text, SkipOnMissingLicense: Boolean, SkipOnMissingPermission: Boolean)]\n```\n### Arguments\nObjectType\nType: ../methods-auto/objecttype/objecttype-option\nSpecifies the type of object that publishes the event to subscribe to.\nObjectId\nType: ../methods-auto/integer/integer-data-type\nSpecifies the ID of the object that that publishes the event to subscribe to. You can specify the object by its ID (integer) or by its name using the syntax `<ObjectType>::<ObjectName>`, such as `Codeunit::MyEventPublisher`. Using the name is the recommended way.\nEventName\nType: ../methods-auto/text/text-data-type\nSpecifies the name of method that publishes the event in the object that is specified by the ObjectId parameter.\nElementName\nType: ../methods-auto/text/text-data-type\nSpecifies the table field that the trigger event pertains to. This argument only requires a value for database trigger events, that is, when the ObjectType is set to table and the EventName argument is a validate trigger event, such as OnAfterValidateEvent.\nSkipOnMissingLicense\nType: ../methods-auto/boolean/boolean-data-type\nSpecifies what happens to the event subscriber method call when the Dynamics 365 Business Central license of the user account that is running the current session does not include the codeunit that contains the subscriber method.\nSkipOnMissingPermission\nType: ../methods-auto/boolean/boolean-data-type\nSpecifies what happens to the subscriber method call when the user account that is running the current session does not have permission to the codeunit that contains the event subscriber method.\n## Remarks\n> TIP\n> Use the Shift+Alt+E shortcut in the AL code editor to open the list of devenv-businessevent-attribute, devenv-integrationevent-attribute, and devenv-internalevent-attribute events. Select an event to insert an event subscriber.\nThe ObjectType value depends on whether you subscribe to a business, integration, internal, or trigger event.\n Business, integration, and internal events are published by event publisher methods. Specify the object that contains the publisher method.\n Trigger events are system events published by table and page objects. Set ObjectType to `ObjectType::Table` for a table trigger event or `ObjectType::Page` for a page trigger event. For ObjectId, use `Database::<ObjectName>` for a table or `Page::<ObjectName>` for a page.\n> IMPORTANT\n> For a table event, specify ObjectId by name with `Database::<ObjectName>`, not `Table::<ObjectName>`.\nFor SkipOnMissingLicense and SkipOnMissingPermission, true skips the subscriber call when the required license or permission is missing. Execution then continues with the next subscriber. The default value, false, raises an error instead.\n## Integration event example\nThis example publishes an integration type event by using the OnAddressLineChanged method. The method takes one Text parameter. The IncludeSender and GlobalVarAccess arguments are set to false.\n```al\ncodeunit 50105 MyEventPublisher\n{\n    [IntegrationEvent(false, false)]\n    procedure OnAddressLineChanged(Line: Text[100])\n    begin\n    end;\n}\n\ncodeunit 50106 MyEventSubscriber\n{\n    [EventSubscriber(ObjectType::Codeunit, Codeunit::MyEventPublisher, 'OnAddressLineChanged', '', true, true)]\n    local procedure MyProcedure(Line: Text[100])\n    begin\n    end;\n}\n```\n## Table trigger event example\nIn this example, the OnAfterValidateLocationCodePurchase method subscribes to the OnAfterValidateEvent table trigger event<../triggers-auto/events/table/devenv-onaftervalidateevent-table-trigger>. It runs after the `\"Purchase Line\"` table's `\"Location Code\"` field is validated.\n```al\ncodeunit 50107 MyEventSubscriber\n{\n    [EventSubscriber(ObjectType::Table, Database::\"Purchase Line\", 'OnAfterValidateEvent', 'Location Code', false, false)]\n    local procedure OnAfterValidateLocationCodePurchase(var Rec: Record \"Purchase Line\")\n    begin\n        // Add logic that runs after the Location Code field is validated.\n    end;\n}\n```\n## Related information\nAL method reference<../methods-auto/library>\n../devenv-events-in-al\n../devenv-publishing-events\n../devenv-raising-events\n../devenv-subscribing-to-events\ndevenv-method-attributes"}