# OnRun (Codeunit) trigger
> Version: _Available or changed with runtime version 1.0._
Runs when a codeunit is run.
## Syntax
```al
trigger OnRun()
begin
    ...
end;
```
## Example
The `OnRun()` trigger is used to initialize the codeunit. A codeunit can be called from another codeunit, a page, or a report. The `OnRun()` trigger is run when the codeunit is called. The following pseudo code illustrates how the `OnRun()` trigger is run when a codeunit is called from a page.
```al
page 50111 MyPage
{
    trigger OnOpenPage();
    begin
        Codeunit.Run(Codeunit::RunMyCode);
    end;
}

codeunit 50110 RunMyCode
{
    trigger OnRun()
    begin
        // Run some code here
    end;
}
```
## Related information
Get Started with AL<../../devenv-get-started>
Developing Extensions<../../devenv-dev-overview>

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/triggers-auto/codeunit/devenv-onrun-codeunit-trigger, 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. https://jonas-paprotka.de/docs/dev-itpro/developer/triggers-auto/codeunit/devenv-onrun-codeunit-trigger/
