Skip to main content

Microsoft Dynamics NAV Coding Guidelines with Examples


We’re the Dynamics NAV developers. We can develop modules, functionalities, fix bugs all the live long day, but, is our code adhere Coding Guidelines, as per Microsoft up there? That’s the end game. How were you guys planning on beating that?


Followings are the catalog of coding violations in 4 major categories or Rules, Readability, Design, Globalization & User eXperience.

    // Readability Rules
    // Rules which ensure that the code is well-formatted and readable.
     Error001 = "Readability: There must be exactly one space character on each side of a binary operator such as := + - AND OR =. The parameter comma operator however, should have no spaces.";
     Error002 = "Readability: There must be no space between a unary operator and its argument (except for the NOT keyword).";
     Error003 = "Readability: There must be no spaces characters before and after [] dimension brackets symbols or :: option symbols.";
     Error004 = "Readability: Do not use blank lines at the beginning or end of any functions, after BEGIN, before END, or inside multiline expressions.";
     Error005 = "Readability: Only use BEGIN..END to enclose compound statements.";
     Error008 = "Readability: Do not use parenthesis in a function call if the function does not have any parameters.";
     Error009 = "Readability: Use parenthesis only to enclose compound expressions inside compound expressions.";
     Error010 = "Readability: Never use curly bracket comments.";
     Error011 = "Readability: Always start comments with // followed by one space character.";
     Error012 = "Readability: In general, use an indentation of two space characters. Logical expressions in the IF, WHILE, and UNTIL parts are indented at least 3, 6, and 6 spaces respectively.";
     Error013 = "Readability: When BEGIN follows THEN, ELSE, DO, it should be on the same line, preceded by one space character.";
     Error015 = "Readability: A CASE action should start on a line after the possibility.";
     Error016 = "Readability: IF and ELSE statements should be on separate lines.";
     Error017 = "Readability: The REPEAT statement should always be alone on a line.";
     Error018 = "Readability: The END, IF, REPEAT, FOR, WHILE, and CASE statement should always start a line.";
     Error020 = "Readability: The last possibility on a CASE statement must be immediately followed by a colon.";
     Error021 = "Readability: Variables declarations should be ordered by type. In general, object and complex variable types are listed first followed by simple variables";
     Error022 = "Readability: Substitute the indented IF THEN ELSE structure with a CASE if there are more than two alternatives.";
     Error023 = "Readability: The IF..THEN pair, WHILE..DO pair, and FOR..DO pair must appear on the same line or the same level of indentation.";
     Error024 = "Readability: The END ELSE pair should always appear on the same line.";
     Error025 = "Readability: A line of code should not have more than one statement.";
     Error035 = "Readability: ELSE should not be used when the last action in the THEN part is an EXIT,BREAK,SKIP,QUIT,ERROR.";
     Error040 = "Readability: Do not nest WITHs that reference different types of objects.";
     Error042 = "Readability: Blanks,periods and other characters that would require quotation marks around a variable must be omitted.";
     Error043 = "Readability: Do not use scope ''.'' qualifier unnecessarily when a variable is already implicitly or explicity scoped.";
     Error050 = "Readability: A line of code should not exceed 132 characters.";
     Error051 = "Readability: There should be no unnecessary empty statements.";
     Error071 = "Readability: Variable must be abbreviated correctly";
     Error072 = "Readability: Variables that refer to a C/AL object must contain the objects name, abbreviated where necessary.";
     Error073 = "Readability: The name of a temporary variable must be prefixed with the word Temp and not otherwise.";
     Error074 = "Readability: TextConst variable names should have a suffix (an approved three-letter suffix: Msg, Tok, Err, Qst, Lbl, Txt) describing usage.";
     Error052 = "Readability: Do not start a line with a binary operator.";
     Error053 = "Readability: Do not end a line with unary operator.";
     Error058 = "Readability: SKIP, BREAK, and QUIT methods should always be placed directly in triggers, never in PROCEDURES";
     Error083 = "Readability: Documentation trigger must be empty.";
     Error084 = "Readability: Do not use ChangeLog tags in code.";
     Error085 = "Readability: Do not use TRUE or FALSE keywords unnecessarily if the expression is already an logical expression.";
     Error086 = "Readability: When calling an object statically use the name, not the number";
    // Design Rules
    // Rules that support proper design    
     Error131 = "Design: The number of parameters passed to a string must match the placeholders.";
     Error136 = "Design: Do not write code that will never be hit.";
     Error137 = "Design: Do not declare variables that are unused.";
     Error138 = "Design: Do not filter using a sequence that does not have a defined index.";
     Error139 = "Design: Do assign a value to a variable whose capacity is smaller.";
     Error140 = "Design: Do assign a value to a parameter variable whose capacity is smaller.";
     Error144 = "Design: Do not use the WITH scope when it has a variable whose name is the same as a local variable. This makes the code confusing.";
     Error147 = "Design: The option values of a parameter variable must match the caller variable option values.";
     Error148 = "Design: The option values of a parameter variable must match the caller variable option values including case and spaces.";
     Error149 = "Design: The value assigned to a variable must be used.";
     Error143 = "Design: Call objects statically whenever possible.";
     Error150 = "Design: Do not declare parameters by reference if their values are never changed.";
     Error151 = "Design: Variables should always be initialised.";
     Error154 = "Design: Refactor";
     Error155 = "Design: Size Length - LANG - {0} - exceeded by {1} on {2}.";
     Error156 = "Design: MaxLength.";
     Error159 = "Design: Functions listed in a HandlerFunction attribute should be declared and marked as handler functions";
     Error160 = "Design: The correct OnLookup trigger code pattern must be used";
     Error157 = "Design: Sizelength exceeded by {0} on {1}.";
     Error170 = "Design: Type conversion conflict";
     Error174 = "Design: Only use IDs that are in the permitted range for W1 development";
     Error175 = "Design: Only use IDs that are in the permitted range for country development";
     Error177 = "Design: Maintainability Index: Do not write functions that have a very low maintainability index. This makes the code hard to maintain.";
     Error178 = "Design: Lines of Code: Do not write functions that have too many lines of code. This makes the code hard to maintain.";
     Error179 = "Design: Coupling:  Do not write functions that have high class coupling. This makes the code hard to maintain.";
     Error180 = "Design: Do not write functions that have high cyclomatic complexity. This makes the code hard to maintain.";
     Error181 = "Design: FINDSET, FIND('+') or FIND('-') should only be used when NEXT is used and vice versa.";
     Error182 = "Design: Only approved DotNet types should be used W1 development.";
     Error186 = "Design: Declare normal procedures in Test Codeunits as local";
     Error187 = "Design: Do not use obsolete data types for W1 development";
    // Globalization Rules 
    // Rules that support world-ready code.
     Error432 = "Localizability: Pass user messages using TextConstants.";
     Error433 = "Localizability: Warning: STRSUBSTNO format string should be TextConstant if the format string contains text.";
     Error434 = "Localizability: Warning: STRSUBSTNO format string should be TextConstant even if the format string doesn't contain text.";
     Error441 = "Localizability: Declare Text Constant as global variables.";
     Error445 = "Localizability: The OptionCaptionML must be filled in for sourceexpression using option data types.";
     Error447 = "Localizability: Option buttons must have the OptionValue filled in.";
     Error446 = "Localizability: All elements with Name property must have the CaptionML filled in.";
     Error476 = "Localizability: Warning: All controls with Name property  must have the CaptionML filled in.";
     Error448 = "Localizability: For user messages,errors etc., use FIELDCAPTION not FIELDNAME and TABLECAPTION not TABLENAME.";
     Error449 = "Localizability: Warning: If STRSUBSTNO result is shown to user you need to use FIELDCAPTION not FIELDNAME (TABLECAPTION not TABLENAME) as for other user messages,errors etc.,.";
     Error450 = "Localizability: Warning: If the result of the operation is shown to user you need to use FIELDCAPTION not FIELDNAME (TABLECAPTION not TABLENAME) as for other user messages,errors etc.,.";
     Error463 = "Localizability: There should be no string concatenation in user messages, errors etc.";
     Error464 = "Localizability: There should be no string concatenation inside STRSUBSTNO";
     Error465 = "Localizability: Warning: Strings should be formatted and not concatenated";
     Error466 = "Localizability: Warning: Constant strings should be defined as text constants";
     Error470 = "Localizability: If there are two or more string format place holders in a row the string should be updated or a comment should be added. More details at: http://sharepointemea/sites/DynamicsNAV/Wiki/Wiki%20Pages/Internationalization%20CAL%20guideliness.aspx";
     Error471 = "Localizability: Text constant should always have a ENU value.";
     Error472 = "Localizability: Place holders should not be followed by text without space or other separator.";
     Error473 = "Localizability: CaptionML should not be specified on a page field for a not system table if it is exactly the same as table field name.";
     Error474 = "Localizability: CaptionML should always be specified on a page field for a system table.";
     Error475 = "Localizability: Warning: CaptionML should be specified on a page field if a filed is a variable and not a table field.";
     Error462 = "Internationalization: The CALCDATE should only be used with DataFormula variables. Alternatively the string should be enclosed using the <> symbols.";
     Error480 = "Localizability: If text constant contains a word in ALL CAPS a comment should be added with information how the word should be translated. More details at: http://sharepointemea/sites/DynamicsNAV/Wiki/Wiki%20Pages/Internationalization%20CAL%20guideliness.aspx";
     Error481 = "Localizability: If text constant contains an accelerator a comment should be added with information how the accelerator should be translated. More details at: http://sharepointemea/sites/DynamicsNAV/Wiki/Wiki%20Pages/Internationalization%20CAL%20guideliness.aspx";
     Error482 = "Localizability: If text constant contains an URI a comment should be added with information how the URI should be translated. More details at: http://sharepointemea/sites/DynamicsNAV/Wiki/Wiki%20Pages/Internationalization%20CAL%20guideliness.aspx";
     Error483 = "Localizability: If text constant contains a html code a comment should be added with information how the html code should be translated. More details at: http://sharepointemea/sites/DynamicsNAV/Wiki/Wiki%20Pages/Internationalization%20CAL%20guideliness.aspx";
     Error484 = "Localizability: Warning: If text constant contains a date/time format a comment should be added with information how the format should be translated. More details at: http://sharepointemea/sites/DynamicsNAV/Wiki/Wiki%20Pages/Internationalization%20CAL%20guideliness.aspx";
     Error485 = "Localizability: If text constant contains only delimiter a comment should be added with information how the delimeter should be translated. More details at: http://sharepointemea/sites/DynamicsNAV/Wiki/Wiki%20Pages/Internationalization%20CAL%20guideliness.aspx";
     Error486 = "Localizability: Warning: Text constant is a sentence fragment";
     Error487 = "Localizability: If text constant contains only one letter a comment should be added with information how the letter should be translated. More details at: http://sharepointemea/sites/DynamicsNAV/Wiki/Wiki%20Pages/Internationalization%20CAL%20guideliness.aspx";
     Error488 = "Localizability: If text constant is only one letter a comment should be added with information how the letter should be translated. More details at: http://sharepointemea/sites/DynamicsNAV/Wiki/Wiki%20Pages/Internationalization%20CAL%20guideliness.aspx";
     Error489 = "Localizability: Text constant should not start or end with a space.";
    // User eXperience Rules
    // Rules that support proper user experience
     Error332 = "UX: Always end MESSAGE or ERROR with a period.";
     Error333 = "UX: Never use FIELDERROR with a period as it is automatically inserted.";
     Error334 = "UX: Always end CONFIRM with a question mark.";
     Error335 = "UX: A non-processing report page action must have an image assigned to it.";



Please find this sheet on How to resolve this Violations with Example.

Comments

  1. Thanks for sharing this impressive blog. Are you looking for the best microsoft dynamics nav support

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
  6. w695v9pldma521 www.replicabag2023.ru w096n9ukbgs829

    ReplyDelete

Post a Comment

Please let me know about your thought on this:

Popular posts from this blog

C/AL Code support in Notepad++

C/AL Code support in Notepad++ Normally NAV object (.txt file) open as plain text in Notepad++ without no keyword highlighting as below. Which completely different from our native Developer Environment thus this editor is not friendly for code readability. But with importing a user defined C/AL language or UDL file in Notepad++, C/AL codes can be supported as other build-in support languages like Java or C#. Same file opened in Notepad++ after importing the UDL file. Now keywords are highlighted in multiple colours which is customizable.

How to use Code Coverage effectively: Part 1/2

:: Optimizing  Code Coverage Page  ::    As a Dynamics NAV developer, we all are fa miliar with this veteran tool for code tracking, The Code Coverage. This tool is very different from debugging as we don’t halt the transaction or process with breakpoints. It simply track all the codes executed during its capturing process from start to stop. It tracks all the code lines and count the line hit during the execution.    In Dynamics NAV previous versions like 2009 SP1 & 2009 R2 it was a great tool for developers to fix calculation issues which doesn't cause runtime error, Third party tool integrations or Tracking codes for developing new functionality in a module.    It feels gloomy to realize how this tool has lost its usability in recent versions. Recently I encountered G/L CONSISTENCY error in a transaction which is nothing but a calculation traggic in one of G/L entry. I tried debugger but unfortunately it didn’t work for me. Then...

Explore Metadata, User Code & User AL Code of Dynamics NAV Virtual Tables

  Dynamics NAV has System or Virtual tables, which is not visible in Object Explorer. Object ID range starting from 2000000001.. 2000000200 and Object Type as Table. What is Virtual Tables?   "A virtual table contains system information. You cannot change the data in virtual tables. You can only read the information. Virtual tables are not stored in the database but are computed by Microsoft Dynamics NAV at run time. Because virtual tables are not stored in the database, you cannot view them directly. To view a virtual table, you must create a list page based on the virtual table." List of Virtual Tables in Dynamics NAV 2016 Object Type Object ID Name Table 2000000001 Object Table 2000000004 Permission Set Table 2000000005 Permission Table 2000000006 Company Table 2000000007 Date Table 2000000009 Session Table 2000000020 Drive Table 2000000022 ...

.al file preview in Windows Explorer preview pane

D on’t like to wait for Visual Studio Code to boot up when you’re looking for a specific .al file? With this trick, you can preview .al files in Windows 10 without opening. .  .. What is File Explorer Preview Pane? First, let's check out the preview pane in File Explorer.  Open File Explorer.  Click on the View tab and then select Preview pane.  Click on a file you wish to view, such as a Word document, Excel sheet, PowerPoint presentation, PDF, or image. The file appears in the preview pane. Increase or decrease the size or width of the file by dragging the separation bar left or right. Modification required to Preview .al file in File Explorer Open Windows Registry Editor (regedit).  Find  Computer\HKEY_CLASSES_ROOT\.al Add New String Value (Right click), Name :  PerceivedType , Value data : text or Download this .reg file and double click to Merge it.  (link below) Download If prompted, click/tap on  Ru...

How to use Code Coverage effectively: Part 2/2

:: Customizing Code Coverage ::    Before beginning this session, if you are new to code coverage, let's have a quick overview. What is Code Coverage?    Code coverage is the means of being able to track which part of the application code has been exercised during an activity. In Microsoft Dynamics NAV, code coverage is recorded by C/AL code line and specifies if a code line was exercised by the activity and the number of times the line of code was executed . How to open Code Coverage?    path: /Departments/Administration/Application Tools    click here open  Code Coverage  directly. How to Start Code Coverage Monitoring?     Before beginning your process open Code Coverage window and click Start. " This starts the code coverage engine, and code coverage is captured. However, you will not be able to see any updated information until you choose Refresh or Stop . The information contains coverage of o...