Variables Declarations Order

Created by Microsoft, Described by waldo

Description

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;

Tips

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