Codeunit Object

A codeunit is a container for AL code that you can use in many application objects. You typically implement business logic in codeunits and call the codeunit from the object that needs to perform that specific logic.

Snippet support

Typing the shortcut tcodeunit will create the basic layout for a codeunit object when using the AL Language extension in Visual Studio Code.

Codeunit example

This codeunit example checks whether a given customer has registered a shoe size. If not, the customer is assigned a shoe size of 42.

codeunit 50113 CreateCustomer
    trigger OnRun();
        r: record Customer;
        if not r.HasShoeSize() then
            r.ShoeSize := 42;

See Also

Developing Extensions
Table Extension Object
Page Extension Object
AL Development Environment