Variables Declarations Order

Created by Microsoft, Described by waldo


Variables declarations should be ordered by type. In general, object and complex variable types are listed first followed by simple variables. The order should be:

  • Record
  • Report
  • Codeunit
  • XmlPort
  • Page
  • Query
  • Notification
  • BigText
  • DateFormula
  • RecordId
  • RecordRef
  • FieldRef
  • FilterPageBuilder

(Ref: Microsoft Docs)

Bad code

    StartingDateFilter: Text;
    Vendor: Record Vendor;

Good code

    Vendor: Record Vendor;
    StartingDateFilter: Text;


The AZ AL Dev Tools/AL Code Outline extension adds two new commands to Visual Studio Code to sorts variables.

  • Sort Variables in the Active Editor : sorts variables in the current editor
  • Sort Variables in the Active Project : sorts variables in the current project
Last modified May 6, 2022: Added Tips section with link to VSCode extension (a1c53ccb) by Frédéric Vercaemst