In this blog we will go through Best practices for AL Code which i normally use while doing AL code.
Microsoft has recommended best practices while developing extensions in AL to ensure the Steadiness of the objects as well as better readability of AL code. This best practice will help in maintaining a uniform structure of the extension which we would be building in AL.
How to maintain Extension Structure?
As per best practice in AL code, we should maintain a single Folder per extension which will include app.json, Launch.json, AL Objects, AL packages, Test toolsets, images.
I have added Folders such as Codeunits, Tables, Pages, Reports to easily access the Objects.
How to do File Naming ?
As shown in the above screenshot. The object name should be
i.e ActionHandler.codeunit.al or CreditBalanceNotification.pageext.al
you can you below recomended abbreviation for different objects.
How to do Formatting AL Code?
Microsoft has recommened
- Use Pascal Case (This means that the first letter of every word in the name is capitalized ). e.g CreditBalanceNotification or OpenCustomer.
- Four space indentation
- New line for Curly bracket.
You can use AL format by ShortCut Shift+Alt+F as shown in below screen shot. For more information on how to use it, see AL Formatter.
How to Format File Structure?
File structure should be uniform through out the extension. Below is the recommended structure.
- Object-specific constructs such as:
- Table fields
- Page layout
- Global variables
- Labels (old Text Constants)
- Global variables
How to do Referencing?
Referencing is done by the object name.
e.g. TempCustomer: Record Customer Tempoprary;
How to do Variable Naming ?
Variable Naming should be PascalCase if temporary variables are used then Temp should be the prefix.
How can we call method?
When calling a method, include one space after each command if you are passing multiple parameters. Parentheses must be specified when you are making a method call or system call such as: Init(), Modify(), Insert() etc.
This are some of the Microsoft Standards which should be followed by the developers to make the code Unified and readable.
To get new updates and learn about Microsoft Dynamics 365 Business Central Microsoft Learn