APPLIES TO: Business Central 2024 release wave 2 and later.
The this keyword is familiar from languages such as C#, JavaScript, and Python. In AL, it provides a self-reference for an object. For codeunits, you can also pass this as an argument or return it as the current codeunit instance. The keyword improves readability by distinguishing object members from local symbols.
Scenarios for using this
The main benefits of using the this keyword are:
- It allows codeunits to pass a reference to the current object (
this) as an argument to another method. - It improves readability by indicating that a referenced symbol is a member of the object itself.
The CodeCop rule AA0248 is enabled by default with a severity level of hidden. Hidden means that it appears as three dots in the editor, but doesn't show up as a diagnostic in the Problems view in Visual Studio Code or in any pipelines. The CodeCop rule identifies places where you can use the this keyword. A code action can update existing code to use the keyword. Learn more about applying code actions in AL code actions.
Note
The current System Application uses the this keyword to reference methods and globals in the same object.