{"title":"Best practices for AL","url":"https://jonas-paprotka.de/docs/dev-itpro/compliance/apptest-bestpracticesforalcode/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/compliance/apptest-bestpracticesforalcode, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/compliance/apptest-bestpracticesforalcode","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Best practices for writing AL code for Business Central.","date":"2026-02-19","meta":{"topic":"best-practice"},"outline":[{"level":1,"title":"Best practices for AL","slug":"best-practices-for-al","at":0,"chars":9057},{"level":2,"title":"Extension structure","slug":"extension-structure","at":710,"chars":593},{"level":2,"title":"File naming","slug":"file-naming","at":1303,"chars":2104},{"level":3,"title":"File naming notation","slug":"file-naming-notation","at":1901,"chars":365},{"level":3,"title":"Type map","slug":"type-map","at":2266,"chars":473},{"level":3,"title":"File naming examples","slug":"file-naming-examples","at":2739,"chars":357},{"level":3,"title":"Examples of object naming","slug":"examples-of-object-naming","at":3096,"chars":311},{"level":4,"title":"Table","slug":"table","at":3126,"chars":56},{"level":4,"title":"Page","slug":"page","at":3182,"chars":54},{"level":4,"title":"Action","slug":"action","at":3236,"chars":109},{"level":4,"title":"Codeunit","slug":"codeunit","at":3345,"chars":62},{"level":2,"title":"Copilot and action names","slug":"copilot-and-action-names","at":3407,"chars":686},{"level":2,"title":"UI strings","slug":"ui-strings","at":4093,"chars":492},{"level":2,"title":"Formatting","slug":"formatting","at":4585,"chars":1223},{"level":2,"title":"Line length","slug":"line-length","at":5808,"chars":182},{"level":2,"title":"Object naming","slug":"object-naming","at":5990,"chars":303},{"level":2,"title":"File structure","slug":"file-structure","at":6293,"chars":260},{"level":2,"title":"Referencing","slug":"referencing","at":6553,"chars":184},{"level":3,"title":"Example","slug":"example","at":6637,"chars":100},{"level":2,"title":"Variable and field naming","slug":"variable-and-field-naming","at":6737,"chars":695},{"level":3,"title":"Example","slug":"example-1","at":7346,"chars":86},{"level":2,"title":"Method declaration","slug":"method-declaration","at":7432,"chars":771},{"level":3,"title":"Example","slug":"example-2","at":7987,"chars":216},{"level":2,"title":"Calling methods","slug":"calling-methods","at":8203,"chars":316},{"level":3,"title":"Example","slug":"example-3","at":8447,"chars":72},{"level":2,"title":"Type definition (colon)","slug":"type-definition-colon","at":8519,"chars":344},{"level":2,"title":"Related information","slug":"related-information","at":8863,"chars":194}],"text":"# Best practices for AL\nThis page defines some of the best practices to follow when writing AL code for Dynamics 365 Business Central. These best practices are additive to rules and guidelines that are caught during compilation of AL code. We recommend following these best practices when developing extensions in AL to ensure consistency and discoverability on file, object, and method naming, as well as better readability of written code.\n> TIP\n> Check out the great work that is going on at https://alguidelines.dev/<https://alguidelines.dev/>. New design patterns and best practices are being established, so join the discussions, and contribute through GitHub<https://github.com/microsoft/alguidelines>.\n## Extension structure\nAn extension is fully contained in a single folder. This folder often contains multiple files, such as app.json and launch.json files, perhaps an image file representing the extension's logo, various folders for source; `\\src`, other resources; `\\res`, and a test folder; `\\test` folder. The extension doesn't need to follow a flat structure, which means that, depending on the number of application files, extra folders can be used in the \"src\" or \"test\" folders to group objects based on their functionality, which can help make maintaining a large AL project easier.\n## File naming\nEach file name should contain the object name (using only characters A-Z, a-z, and 0-9), the object type, and the `.al` file extension. In your extension, the name of each new application object (table, page, codeunit), can contain a prefix or suffix.\nThe CodeCop analyzer suggests that the object name is part of the file name, which is encouraged as a best practice. Adding any affixes to the file names is voluntary.\n> NOTE\n> If you're submitting an app to Marketplace, you must follow the guidance in the Technical validation checklist<../developer/devenv-checklist-submission>.\n### File naming notation\nFollow the syntax for file naming as shown in the table:\nFull objects|Extensions\n`<ObjectNameSuffix>.<FullTypeName>.al`|`<ObjectNameSuffix>.<FullTypeName>Ext.al`\n`<PrefixObjectName>.<FullTypeName>.al`|`<PrefixObjectName>.<FullTypeName>Ext.al`\n`<ObjectNameExcludingAffix>.<FullTypeName>.al`|`<ObjectNameExcludingAffix>.<FullTypeName>Ext.al`\n### Type map\nUse the listed abbreviations for each type of object in the file naming:\nObject|Abbreviation\nPage|Page\nPage Extension|PageExt\nPage Customization|PageCust\nCodeunit|Codeunit\nTable|Table\nTable Extension|TableExt\nXML Port|Xmlport\nReport|Report\nRequest Page|RequestPage\nQuery|Query\nEnum|Enum\nEnum Extension|EnumExt\nControl Add-ins|ControlAddin\nDotnet|Dotnet\nProfile|Profile\nInterface|Interface\nPermission Set|PermissionSet\nPermission Set Extension|PermissionSetExt\n### File naming examples\nFor the listed objects in the table, these examples show how to name the files.\nObject name|File name\ncodeunit 70000000 MyPrefixSalesperson|MyPrefixSalesperson.Codeunit.al\npage 70000000 MyPrefixSalesperson|MyPrefixSalesperson.Page.al\npageextension 70000000 MyPrefixSalesperson extends \"Customer Card\"|MyPrefixSalesperson.PageExt.al\n### Examples of object naming\n#### Table\n```al\ntable 70000000 MyPrefixSalesperson\n```\n#### Page\n```al\npage 70000000 MyPrefixSalesperson\n```\n#### Action\n```al\nactions\n{\n    addafter(ApprovalEntries)\n    {\n        action(MyPrefixVacation)\n    }\n}\n```\n#### Codeunit\n```al\ncodeunit 70000000 MyPrefixSalesperson\n```\n## Copilot and action names\nTrailing whitespaces are allowed in action names, meaning that you don't get a compiler error. For example these names are accepted:\n```al\ngroup(\"CopilotActionGroup  \")\n{\n    action(\"Suggest Sales Lines   \")\n    {\n        // Code that generates sales lines suggestions\n    }\n}\n```\nHowever, these trailing whitespaces are trimmed internally and aren't recognized by Copilot. To ensure that Copilot works correctly with your feature, you must avoid trailing spaces in action names. Instead, write the code like this:\n```al\ngroup(\"CopilotActionGroup\")\n{\n    action(\"Suggest Sales Lines\")\n    {\n        // Code that generates sales lines suggestions\n    }\n}\n```\n## UI strings\nWhen writing UI strings, such as labels and captions, we recommend the following best practices:\n Use sentence case for labels and captions, when a verb is present and the string can be read as a sentence. For example, \"Calculate total\", \"Generate report\", \"Turn index off\", \"Submit order\".\n Use title case for labels and captions when a verb isn't present, or the string can't be read as a sentence. For example, \"Customer Card\", \"General Ledger\", \"Dimensions\", \"Sales Order\".\n## Formatting\nWe recommend keeping your AL code properly formatted as follows:\n Use all lowercase letters for reserved language keywords. Built-in methods and types aren't included in this rule because they're written using Pascal case.\n Use four spaces for indentation.\n Curly brackets should always start on a new line. If there's only one property, it can be placed on a single line.\nThe following example illustrates these formatting rules.\n```al\npage 123 PageName\n{\n    actions\n    {\n        area(Processing)\n        {\n            action(ActionName)\n            {\n                trigger OnAction()\n                begin\n                end;\n            }\n        }\n    }\n\n    var\n        TempCustomer: Record Customer temporary;\n\n    [EventSubscriber(ObjectType::Page, Page::\"Item Card\", 'OnAfterGetCurrRecordEvent', '', false, false)]\n    local procedure OnOpenItemCard(var rec: Record Item)\n    var\n        OnRecord: Option \" \", Item, Contact;\n    begin\n        EnablePictureAnalyzerNotification(rec.\"No.\", OnRecord::Item);\n    end;\n}\n\n```\nThe AL Language extension for Microsoft Dynamics 365 Business Central offers users the option to automatically format their source code. See ../developer/devenv-al-formatter.\n## Line length\nIn general, there's no restriction on line length, but lengthy lines can make the code unreadable. We recommend that you keep your code easily scannable and readable.\n## Object naming\nObject names should be prefixed, starting with the feature or group name, followed by the logical name, as illustrated in the following examples:\n `Intrastat extension validation codeunit for Denmark`\n `codeunit 123 \"IntrastatDK Validation\"`\n> NOTE\n> The \"MS - \" prefix isn't required.\n## File structure\nInside an .al code file, the structure for all objects must follow the sequence:\n1. Properties\n2. Object-specific constructs such as\n  Table fields\n  Page layout\n  Actions\n  Triggers\n3. Global variables\n  Labels\n  Global variables\n4. Methods\n## Referencing\nIn AL, objects are referenced by their object name, not by their ID.\n### Example\n```al\nPage.RunModal(Page::\"Customer Card\", ...)\n\nvar\n    Customer: Record Customer;\n```\n## Variable and field naming\nFor variables they must:\n Be named using PascalCase\n Have the Temp prefix if they're temporary variables\n Include the object name in the name (for objects)\nFurthermore:\n Field and variable names shouldn't include wildcard symbols, such as `%` and `&`. This might break features such as export using Excel or RapidStart.\n Name fields using A-Z, a-z, and 0-9 and use Caption and xliff files to display the field appropriately. See ../developer/devenv-work-with-translation-files.\n Using English as the language for naming improves the ability to troubleshoot issues that may arise.\n### Example\n```al\nTempCustomer: Record Customer temporary;\nVendor: Record Vendor;\n```\n## Method declaration\nTo declare a method, follow these guidelines:\n Include a space after a semicolon when declaring multiple arguments.\n Semicolons can be used at the end of the signature/method header. If you use a snippet, the semicolons aren't automatically added.\n Methods should be named using PascalCase, like variables. However, this isn't a mandatory rule.\n There must be a blank line between method declarations. If you format your code using the ../developer/devenv-al-formatter tool, the autoformatter sets the blank line between procedures.\n### Example\n```al\nlocal procedure MyProcedure(Customer: Record Customer; Int: Integer)\nbegin\nend;\n\n// Blank line between methods\n\nlocal procedure MyProcedure2(Customer: Record Customer; Int: Integer)\nbegin\nend;\n\n```\n## Calling methods\nWhen calling a method, include one space after each command if you're passing multiple parameters. Parentheses must be specified when you're making a method call or system call such as: `Init()`, `Modify()`, `Insert()`, etc.\n### Example\n```al\nMyProcedure();\nMyProcedure(1);\nMyProcedure(1, 2);\n```\n## Type definition (colon)\nWhen you declare a variable or a parameter, the name of that variable or parameter must be immediately followed by a colon, then a single space, and then the type of the variable/parameter as illustrated in the example.\n```al\nvar\n    Number: Integer;\n\nlocal procedure MyProcedure(a: Integer; b: Integer): Integer\n```\n## Related information\nChecklist for submitting your app<../developer/devenv-checklist-submission>\nRules and guidelines for AL code<apptest-overview>\n../developer/devenv-using-code-analysis-tool"}