This post is part of the New Functionality In Microsoft Dynamics 365 Business Central 2024 Wave 2 series in which I am taking a look at the new functionality introduced in Microsoft Dynamics 365 Business Central 2024 Wave 2.
The 4th of the new functionality in the Development section is use the ‘this’ keyword for codeunit self reference.
A new ‘this’ keyword is introduced as known from other languages. The keyword supports passing the current object as arguments to methods, which until now has only been possible with less optimal workarounds. In addition, the use of the this
keyword improves readability for bigger methods where it can be difficult to see if a variable is global or local scope..
Enabled for: Admins, makers, marketers, or analysts, automatically
Public Preview: Oct 2024
General Availability: Oct 2024
Feature Details
Microsoft have added support for the this
keyword for self-reference on all objects, as known from other programming languages.
The main benefits of using the this
keyword are that it
- Allows codeunits to pass a reference to this (which is itself) as an argument to another method.
- Improves readability by signaling that a referenced symbol is a member on the object itself.
A new CodeCop rule AA0248 is added and enabled by default with severity ‘hidden’. ‘Hidden’ means that it shows up as three dots in the editor, but not as a diagnostics in the Problem view in Visual Studio Code, or in pipelines. There’s also a workspace-wide CodeFixer to update existing code to use the this
keyword.
The System Application is converted to use this
for referencing methods and globals in the same object.