OnRun (Codeunit) trigger

Version: Available or changed with runtime version 1.0.

Runs when a codeunit is run.

Syntax

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.

page 50111 MyPage
{
    trigger OnOpenPage();
    begin
        Codeunit.Run(Codeunit::RunMyCode);
    end;
}

codeunit 50110 RunMyCode
{
    trigger OnRun()
    begin
        // Run some code here
    end;
}

Get Started with AL
Developing Extensions