{"title":"Session.BindSubscription(Codeunit) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/session/session-bindsubscription-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/session/session-bindsubscription-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/session/session-bindsubscription-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":"Binds the event subscriber methods in the codeunit to the current codeunit instance for handling the events that they subscribe to.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"Session.BindSubscription(Codeunit) Method","slug":"sessionbindsubscriptioncodeunit-method","at":0,"chars":2134},{"level":2,"title":"Syntax","slug":"syntax","at":315,"chars":150},{"level":2,"title":"Parameters","slug":"parameters","at":465,"chars":110},{"level":2,"title":"Return Value","slug":"return-value","at":575,"chars":304},{"level":2,"title":"Remarks","slug":"remarks","at":879,"chars":482},{"level":2,"title":"Example","slug":"example","at":1361,"chars":638},{"level":2,"title":"Related information","slug":"related-information","at":1999,"chars":135}],"text":"# Session.BindSubscription(Codeunit) Method\n> Version: _Available or changed with runtime version 1.0._\nBinds the event subscriber methods in the codeunit to the current codeunit instance for handling the events that they subscribe to. This essentially activates the subscriber functions for the codeunit instance.\n## Syntax\n```al\n[Ok := ]  Session.BindSubscription(Codeunit: Codeunit)\n```\n> NOTE\n> This method can be invoked without specifying the data type name.\n## Parameters\nCodeunit\nType: ../codeunit/codeunit-data-type\nThe codeunit that contains the event subscribers.\n## Return Value\n*[Optional] Ok*\nType: ../boolean/boolean-data-type\ntrue if the event subscriber methods bind successfully to the codeunit instance and no errors occurred, otherwise false. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.\n## Remarks\nYou can only call this method on codeunits that have the ../../properties/devenv-eventsubscriberinstance-property set to Manual.\nThe codeunit instance that event subscribers are bound to will be this exact instance. Events will be raised on this instance. You can't bind the same instance more than once, but you can bind multiple instances of the same codeunit. This condition will result in an event subscriber call on each bound instance when a given event is raised.\n## Example\nThe following sample code illustrates a typical use of the BindSubscription method.\n```al\nprocedure MyFunction()\nvar\n    Subscriber: Codeunit Subscriber;\nbegin\n    // Set global information on the subscriber codeunit if required\n    // You can rely on the instance being the same as the one receiving the event subscriber call\n\n    Subscriber.MySetGlobalInfo(123); //info you can later test in the subscriber event method\n    BindSubscription(Subscriber);\n    DoSomething();  // After binding, all subscriptions on Subscriber are \"active\".\nend; // Notice, that when Subscriber goes out of scope, all bindings are removed.\n\n```\n## Related information\nsession-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}