Best Practices
Best Practices
Dynamics AX 2012
Overview
• The X++ compiler checks the code for best practice issues.
• These issues can result in best practice errors, warnings, or
informational messages.
• These best practices apply to the following
• Programming in the standard application
• Certified solutions
Best Practices Checks
• Check your own code and application objects for compliance
with the best practices for Microsoft Dynamics AX.
• Select Tools > Options.
• Click the Development area, in the toolbar, click the Best
practices button.
• In the Warning level list, select the checks that you want to
perform.
• This will mean that best practices are checked when you
compile or check in an object.
• You can also check best practices for one or more nodes in the
Application Object Tree (AOT): right-click the node, and then
select Add-Ins > Check Best practices.
Best Practices Results
• Results are displayed in an Infolog, with the following severity
code:
• Information: Things that might be nice to know (shown in blue).
• Warnings: Things that you should strongly consider fixing (shown
in yellow).
• Errors: Things that should definitely be fixed (shown in red).
• If you double-click on an error message, this will open the
code editor.
Disable Individual Warnings and Errors
• Action pane: The action pane is displayed at the top of each list
page. The action pane displays all the actions that are specific to the
list page, and each action can either relate to the selected record or
be independent of it.
Tables and Maps
• Metadata
• The table must have a 'Label' defined from a label file.
• The table must have a ‘HelpText’ defined from a label file.
• Title fields should be defined.
• The tables’ group property should be set properly according to its
purpose.
• The 'CacheLookup' field should be filled in.
• Table ‘FormRef” should be set if applicable.
• The 'table contents' should be set if this table contains base or
default data.
• Metadata Indexes
• Assign a unique index to each table.
• Add as few indexes as possible and maintain query performance.
• Strongly consider designating one of the indexes as the cluster index.
Tables and Maps
• Field Metadata
• All fields that are part of the primary key/ index should be
mandatory and should not be editable.
• All fields should extend from an extended data type and should
be part of at least one field group.
• The field must have a 'Label' defined from a label file.
• The field must have a 'HelpText' defined from a label file.
• Field Groups
• The ‘Auto Report’ field group must contain at least one field.
• All new field groups must have 'Label' defined from a label file.
• Additional field groups should be created that logically group like
fields that can be used on form and reports.
Tables and Maps
• Delete Actions
• To ensure referential integrity between tables (i.e. don't leave
orphaned records in a details table when the header is deleted) you
must set the delete action on the table.
• Methods
• Static ‘find’ and ‘exist’ methods should exist for the table’s primary
search key.
• A static find method should exist that fetch other related tables using
the foreign key contained in table.
• Property
• Table Group and Cache Lookup should be defined
• Relation should exists for each FK
• Should define the relation property as per the business process.
• You will get a best practices error if you create a relation on a table
but do not add any fields to it.
• Tmp related table should set as “in Memory”
Views
• Property
• The view must have a 'Label' defined from a label file.
• Title fields should be defined.
• The views’ group property should be set properly according to its
purpose.
• The view should be attached to a configuration and security key.
• View ‘FormRef” should be set if applicable.
• Note: This is critical for the “Go to main” functionality.
• Field Properties
• The field must have a 'Label' defined from a label file.
• The field must have a 'HelpText' defined from a label file.
• Field Groups
• The ‘Auto Report’ field group must contain at least one field.
• All new field groups must have 'Label' defined from a label file.
• Additional field groups should be created that logically group like
fields that can be used on form and reports.
Extended Data Types
• Use an extended data type wherever possible.
• Do not directly use the system data
types recID or tableID. Use the extended data
type RefRecId or an extended data type derived fromRefRecId.
• Property
• The EDT must have a 'Label' defined from a label file.
• The EDT must have a 'HelpText' defined from a label file.
• Configuration key should be defined.
• Do not try to modify the parents EDT property
Base Enums
• Property
• The Base Enum must have a 'Label' defined from a label file.
• The Base Enum must have a 'HelpText' defined from a label file.
• Configuration key should be defined.
• It should start as Zero value
Configuration and Security Keys
• Property
• The Configuration & Security Keys must have a 'Label' defined
from a label file.
• New modules Security Keys should be created in similar fashion
and construction as standard AX based on menu structure and
sections (i.e. Daily, Inquiries, Reports, etc.)
• Security keys are obsolete in Microsoft Dynamics AX 2012 and
only exist to use for reference during a code upgrade. There is
a new security framework, which is called role-based security.
Classes
• Methods
• All text referenced in the class should be defined from a label in a
label file, (i.e.: messages, “infolog” information, etc..). Text constants
should not be used.
• Use private class methods instead of local functions (local methods)
wherever possible. Local functions cannot be overridden,
overlayered, or reused.
• Check for good SQL syntax.
• Ensure that you are using proper class type construct.
• You must specify an access level for your method.
• Check for and remove unnecessary comments.
• Remove unused variables that are part of the modification layer,
• Dangling semicolon should not be used in methods.
• Property
• The run on property should be set appropriately based on its
functionality.
Macros
• Macro names should start with an uppercase letter.
• You must only use macros for declaring constants or libraries
of constants that should be available everywhere in the
application.
• The #localmacro directive is the best choice when you want to
substitute part or all of an X++ statement into several
locations in your code.
• For example, a recurring part of an SQL where clause can be
reused as a macro.
Forms
• Methods
• Avoid putting any code in the Active method.
• Try to implement the Max code logic in table or Class level instead of
Form methods
• Data Sources
• The name of the data source should be the same as the table name.
• Note: When the same table is used multiple times on a form then the
name should be reflective to the purpose of that table on the form.
• Design
• When you design forms, their properties should retain
their Auto or Default settings. This is the primary form-design rule.
• Caption must be defined from a label file.
• Form should have a title data source defined.
• Design list elements name should be meaningful.
Reports
• Use query based reports when possible.
• Use a precision design for all reports. An auto design is a good
start point to create a precision design for a report. An auto
design will not create medium or complex reports
• Avoid using RDP classes when the data for the report is in a
table and the report dataset can use the table
Jobs
• Jobs should not be used in production code.
Security
• New/Existing
• New Role
• ‘Label’ must be defined from a label file.
• ‘Description’ must be defined from a label file.
• It should tag with Privileges, Duties and TPF Table as per business
Rule
• Privileges
• ‘Label’ must be defined from a label file.
• ‘Description’ must be defined from a label file.
• It should tag with Entry Point with proper Access Level
• Duties
• ‘Label’ must be defined from a label file.
• ‘Description’ must be defined from a label file.
• It should tag with Privileges
Menus and Menu Items
• All runable elements you create must have a corresponding
menu item, with the same name as the element.
• Property
• ‘Label’ must be defined from a label file.
• ‘HelpText’ must be defined from a label file.
• Ensure proper use of the ‘Run On’ property.
• Object Type should be defined.
• Define the permission type if required.
Query Programming
• Are queries built in the tree where possible, instead of
building the queries from code?
• Are the queryValue(), SysQuery::value(), SysQuery::range() etc.
methods used when working with query ranges?
AIF Best Practice Checks
• Make sure the document class is prefixed with AxD
• Note: If the query is defined the AIF wizard will automatically take
care of this else when user creates a class manually always prefix
the class with AxD.
• All the fields in a table must have set and parm methods
accordingly.
• Note:the AxBusinessClass (i.e. Ax <Table Name>) should have the
set/parm methods accordingly If user has added a new field in
table then set/parm methods need to add accordingly.
BP Case Study
• Fix all BP errors
• Create BP Case study report for errors.
• Perform code review for Naming Convention , Formatting &
other BP guidelines. Add your comments into BP Case Study
Report.
THANKS