Codeunit
Codeunit: Object type in Dynamics NAV and Business Central that contains program logic but has no user interface, for example posting routines.
Also: codeunits
A codeunit is an object type in Dynamics NAV and Business Central that contains program logic. Unlike tables or pages, it stores no data and has no user interface. It bundles functions that other objects call.
What is a codeunit used for in Business Central?
A codeunit holds program logic that is needed in several places. A large part of the standard logic sits in codeunits, such as the routines that post sales documents or determine prices. Custom codeunits encapsulate calculations, checks and interfaces, so that they are maintained in one place and used repeatedly.
What are events and subscribers in a codeunit?
A codeunit can subscribe to events of the standard. The standard signals at certain points that something is happening, for example before or after posting. The subscribing codeunit reacts to it without changing the standard code. Extensions in Business Central are based on this principle.
What happens to codeunits when moving from Dynamics NAV?
In NAV a codeunit is written in C/AL, in Business Central in AL. Custom codeunits are therefore converted. Where they used to change standard code, a switch to event subscribers is usually needed. Some custom codeunits also become unnecessary because the standard now offers the function itself.