SlideShare a Scribd company logo
AX 2012 X++ Code Best Practices 
Best practice is a method or technique that has consistently shown results superior to 
those achieved with other means, and that is used as a benchmark. In addition, a "best" 
practice can evolve to become better as improvements are discovered. Best practice is 
considered by some as a business buzzword, used to describe the process of 
developing and following a standard way of doing things that multiple organizations can 
use. 
Best practices are used to maintain quality as an alternative to mandatory legislated 
standards and can be based on self-assessment or benchmarking.
AX 2012 X++ Code Best Practices 
Index 
Select Statements 
Comments 
Extra Semicolon 
Constants 
User interface labels 
System Oriented Constants 
Dates 
Try catch Block 
Transactions 
Conditional Statements 
XML Documentation 
Avoiding Potential Security Issues 
Other Best Practices 
References
AX 2012 X++ Code Best Practices 
Select Statements 
➔ The index, order by, and where statements are indented once relative to the 
select or while select statements. 
➔ The where expression is structured in a column. 
➔ The Boolean operators (&&) are at the beginning of the line (and in columns). 
➔ The while select block has braces even though it contains only one statement. 
➔ The braces are at the same column position as the while block. 
➔ The uppercase- and lowercase-name standards are adhered to. 
Comments 
➔ To find comments in the source (both // .. and /* .. */), use the Find 
dialog to search for methods containing the text (regular expression): 
/[/*] 
➔ Comments should not include: 
◆ Dates 
◆ Names 
◆ Aliases 
◆ Version or layer references 
◆ Bug numbers – unless it is a workaround, or unless the code 
could appear inappropriate if you didn't know that it was for a 
bug fix. 
◆ Politically or culturally sensitive phrases 
➔ If you put a comment at the start of the method to describe its 
purpose and use, you can use block comments (/* */) 
Extra Semicolon 
➔ From Microsoft Dynamics AX 2012 onward, you are no longer required 
to put a semicolon on an empty line after the last variable declaration. 
Adding the semicolon is no longer an X++ best practices.
AX 2012 X++ Code Best Practices 
Constants 
Use Intrinsic functions whenever possible. Intrinsic functions are metadata 
assertion functions. They take arguments that represent entities in the 
Application Object Tree (AOT), and validate these arguments at compile time 
details 
➔ User interface labels 
this must be complete sentences. Do not build sentences using more 
than one label, or other constants or variables under program control 
(do not use concatenation). 
Description description = "@SYS12345" 
Use strFmt to format user interface text. 
➔ System Oriented Constants 
Do not use labels. You will get a warning if a label is used inside single 
quotes. 
Dates 
➔ Use only strongly typed (date) fields, variables, and controls (do 
not use str or int). 
➔ Use Auto settings in date formatting properties. 
➔ Use DateTimeUtil::getSystemDateTime instead of systemDateGet 
or today 
➔ Avoid using date2str for performing date conversions. 
➔ Most application logic should use the system function 
systemDateGet , which holds the logic business date of the 
system (this can be set from the status bar). 
➔ The system function today() should be used only where the 
actual machine date is needed 
➔ use strFmt or date2Str with -1 in all the formatting parameters. 
This ensures that the date is formatted in the way that the user 
has specified in Regional Settings
AX 2012 X++ Code Best Practices 
Try catch Block 
➔ Always create a try/catch deadlock/retry loop around database 
transactions that might lead to deadlocks. 
➔ Whenever you have a retry, all the transient variables must be set 
back to the value they had just before the try. The persistent variables 
(that is, the database and the Infolog) are set back automatically by 
the throw that leads to the catch/retry 
try 
{ 
this.createJournal(); 
this.printPosted(); 
} 
catch (Exception::Deadlock) 
{ 
this.removeJournalFromList(); 
retry; 
} 
➔ The throw statement automatically initiates a ttsAbort, which is a 
database transaction rollback. 
➔ The throw statement should be used only if a piece of code cannot do 
what it is expected to do. The throw statement should not be used for 
more ordinary program flow control. 
Transactions 
➔ ttsBegin and ttsCommit must always be used in a clear and well-balanced 
manner. Balanced ttsBegin and ttsCommit statements are 
the following: 
◆ Always in the same method. 
◆ Always on the same level in the code. 
➔ Avoid making only one of them conditional. 
➔ Use throw, if a transaction cannot be completed. 
➔ Do not use ttsAbort; use throw instead. 
Conditional Statements 
➔ If you have an if...else construction, then use positive logic:
AX 2012 X++ Code Best Practices 
Avoid: 
if (!false) 
{ 
... 
} 
XML Documentation 
The following table lists the best practices error messages and how to fix the 
errors. 
Message Message type How to fix the error or warning 
Tag '%1' in XML 
documentation is not 
supported. 
Warning Add XML documentation. For information 
about how to add XML documentation, see 
How to: Add XML Documentation to X++ 
Source Code. Because this is a warning 
instead of an error, this is optional. 
Unsupported tag '%1' 
in XML documentation. 
Error or 
Warning 
Check the casing of the XML tags if this is 
reported as an error. If this is reported as a 
warning, an unsupported tag is present. 
Remove unsupported tags. 
Missing tag '<param 
name="%1">' in XML 
documentation. 
Error Add <param> tags to the XML header 
template. The <param> tag must have a 
name attribute. The value of the attribute is 
case-sensitive and must match the casing in 
the method. 
Missing tag 'returns' in 
XML documentation. 
Error Add <returns> tags to the XML header 
template. 
Missing tag 'summary' 
in XML documentation. 
Error Add <summary> tags to the XML header 
template. 
Tag '%1' exists more 
than once in XML 
documentation. 
Error Delete extra tags. This applies only when 
multiple tags are not appropriate.
AX 2012 X++ Code Best Practices 
Tag '<param 
name="%1">' has no 
content in XML 
documentation. 
Error Add a description of the parameter between 
the <param> tags. 
Tag '<param 
name="%1">' in XML 
documentation doesn't 
match actual 
implementation. 
Error Fix the value of the name attribute. It is case-sensitive 
and must match the casing in the 
method. 
Tag 'exception' has no 
content in XML 
documentation. 
Error Add a description of the exception between 
the <exception> tags. 
Tag 'permission' has no 
content in XML 
documentation. 
Error Add a description of the required permission 
between the <permission> tags. 
Tag 'remarks' has no 
content in XML 
documentation. 
Error Add content between the <remarks> tags or 
delete the <remarks> tags. 
Tag 'returns' has no 
content in XML 
documentation. 
Error Add a description of the return value between 
the <returns> tags. 
Tag 'returns' in XML 
documentation doesn't 
match actual 
implementation. 
Error Delete the <returns> tags and the description 
of the return value. 
Tag 'summary' has no 
content in XML 
documentation. 
Error Add a topic summary between the 
<summary> tags. 
XML documentation is 
not well-formed. 
Error Make sure that there are no mistakes in the 
XML tags. Each opening tag must have a 
corresponding closing tag.
AX 2012 X++ Code Best Practices 
Tag 'seealso' has no 
content in XML 
documentation. 
Error Add content between the <seealso> tags or 
delete the <seealso> tags. 
No XML documentation 
for this method. 
Error XML documentation has not been written for 
this method.
AX 2012 X++ Code Best Practices 
Avoiding Potential Security Issues 
➔ Certain APIs that ship with Microsoft Dynamics AX use Code Access 
Security. When these APIs are run on the server, a class derived from 
CodeAccessPermission must be used. This helps make the APIs more 
secure. 
➔ When you upgrade from a previous version of Microsoft Dynamics AX, 
you must modify calls to these APIs to ensure that the code executes 
correctly. details 
Other Best Practices 
Best practice checks help to make sure that the best practice guidelines are 
followed. Use the Best practice parameters form to select which best practice 
checks to verify. 
Read more best practice parameters 
References 
● http://msdn.microsoft.com/en-us/library/aa855488.aspx
Ad

More Related Content

What's hot (20)

Sql Basics And Advanced
Sql Basics And AdvancedSql Basics And Advanced
Sql Basics And Advanced
rainynovember12
 
Dynamics ax 2012 development overview
Dynamics ax 2012 development overviewDynamics ax 2012 development overview
Dynamics ax 2012 development overview
Ali Raza Zaidi
 
Window functions in MySQL 8.0
Window functions in MySQL 8.0Window functions in MySQL 8.0
Window functions in MySQL 8.0
Mydbops
 
Odata
OdataOdata
Odata
Monalisa Patel
 
SQL Server Index and Partition Strategy
SQL Server Index and Partition StrategySQL Server Index and Partition Strategy
SQL Server Index and Partition Strategy
Hamid J. Fard
 
Basic Sql Handouts
Basic Sql HandoutsBasic Sql Handouts
Basic Sql Handouts
jhe04
 
SQL window functions for MySQL
SQL window functions for MySQLSQL window functions for MySQL
SQL window functions for MySQL
Dag H. Wanvik
 
SQL
SQLSQL
SQL
Vineeta Garg
 
Indexes and Indexing in Oracle 12c
Indexes and Indexing in Oracle 12cIndexes and Indexing in Oracle 12c
Indexes and Indexing in Oracle 12c
Oren Nakdimon
 
Microsoft dynamics ax 2012 development introduction part 1/3
Microsoft dynamics ax 2012 development introduction part 1/3Microsoft dynamics ax 2012 development introduction part 1/3
Microsoft dynamics ax 2012 development introduction part 1/3
Ali Raza Zaidi
 
Introduction to CSS3
Introduction to CSS3Introduction to CSS3
Introduction to CSS3
Doris Chen
 
[APJ] Common Table Expressions (CTEs) in SQL
[APJ] Common Table Expressions (CTEs) in SQL[APJ] Common Table Expressions (CTEs) in SQL
[APJ] Common Table Expressions (CTEs) in SQL
EDB
 
Oracle BI Publsiher Using Data Template
Oracle BI Publsiher Using Data TemplateOracle BI Publsiher Using Data Template
Oracle BI Publsiher Using Data Template
Edi Yanto
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
Dhani Ahmad
 
Sql Tutorials
Sql TutorialsSql Tutorials
Sql Tutorials
Priyabrat Kar
 
Oracle Index
Oracle IndexOracle Index
Oracle Index
Madhavendra Dutt
 
T-SQL Overview
T-SQL OverviewT-SQL Overview
T-SQL Overview
Ahmed Elbaz
 
Cubing and Metrics in SQL, oh my!
Cubing and Metrics in SQL, oh my!Cubing and Metrics in SQL, oh my!
Cubing and Metrics in SQL, oh my!
Julian Hyde
 
Tableau - Learning Objectives for Data, Graphs, Filters, Dashboards and Advan...
Tableau - Learning Objectives for Data, Graphs, Filters, Dashboards and Advan...Tableau - Learning Objectives for Data, Graphs, Filters, Dashboards and Advan...
Tableau - Learning Objectives for Data, Graphs, Filters, Dashboards and Advan...
Srinath Reddy
 
Oracle Forms: Non input Items
Oracle Forms:  Non input ItemsOracle Forms:  Non input Items
Oracle Forms: Non input Items
Sekhar Byna
 
Dynamics ax 2012 development overview
Dynamics ax 2012 development overviewDynamics ax 2012 development overview
Dynamics ax 2012 development overview
Ali Raza Zaidi
 
Window functions in MySQL 8.0
Window functions in MySQL 8.0Window functions in MySQL 8.0
Window functions in MySQL 8.0
Mydbops
 
SQL Server Index and Partition Strategy
SQL Server Index and Partition StrategySQL Server Index and Partition Strategy
SQL Server Index and Partition Strategy
Hamid J. Fard
 
Basic Sql Handouts
Basic Sql HandoutsBasic Sql Handouts
Basic Sql Handouts
jhe04
 
SQL window functions for MySQL
SQL window functions for MySQLSQL window functions for MySQL
SQL window functions for MySQL
Dag H. Wanvik
 
Indexes and Indexing in Oracle 12c
Indexes and Indexing in Oracle 12cIndexes and Indexing in Oracle 12c
Indexes and Indexing in Oracle 12c
Oren Nakdimon
 
Microsoft dynamics ax 2012 development introduction part 1/3
Microsoft dynamics ax 2012 development introduction part 1/3Microsoft dynamics ax 2012 development introduction part 1/3
Microsoft dynamics ax 2012 development introduction part 1/3
Ali Raza Zaidi
 
Introduction to CSS3
Introduction to CSS3Introduction to CSS3
Introduction to CSS3
Doris Chen
 
[APJ] Common Table Expressions (CTEs) in SQL
[APJ] Common Table Expressions (CTEs) in SQL[APJ] Common Table Expressions (CTEs) in SQL
[APJ] Common Table Expressions (CTEs) in SQL
EDB
 
Oracle BI Publsiher Using Data Template
Oracle BI Publsiher Using Data TemplateOracle BI Publsiher Using Data Template
Oracle BI Publsiher Using Data Template
Edi Yanto
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
Dhani Ahmad
 
Cubing and Metrics in SQL, oh my!
Cubing and Metrics in SQL, oh my!Cubing and Metrics in SQL, oh my!
Cubing and Metrics in SQL, oh my!
Julian Hyde
 
Tableau - Learning Objectives for Data, Graphs, Filters, Dashboards and Advan...
Tableau - Learning Objectives for Data, Graphs, Filters, Dashboards and Advan...Tableau - Learning Objectives for Data, Graphs, Filters, Dashboards and Advan...
Tableau - Learning Objectives for Data, Graphs, Filters, Dashboards and Advan...
Srinath Reddy
 
Oracle Forms: Non input Items
Oracle Forms:  Non input ItemsOracle Forms:  Non input Items
Oracle Forms: Non input Items
Sekhar Byna
 

Viewers also liked (15)

Microsoft Dynamics AX 2012 - Development Introduction Training - Part 3/3
Microsoft Dynamics AX 2012 - Development Introduction Training - Part 3/3Microsoft Dynamics AX 2012 - Development Introduction Training - Part 3/3
Microsoft Dynamics AX 2012 - Development Introduction Training - Part 3/3
Fabio Filardi
 
AX 2012: All About Lookups!
AX 2012: All About Lookups!AX 2012: All About Lookups!
AX 2012: All About Lookups!
MAnasKhan
 
Microsoft Dynamics AX 2012 - Development Introduction Training - Part 2/3
Microsoft Dynamics AX 2012 - Development Introduction Training - Part 2/3Microsoft Dynamics AX 2012 - Development Introduction Training - Part 2/3
Microsoft Dynamics AX 2012 - Development Introduction Training - Part 2/3
Fabio Filardi
 
Microsoft dynamics ax 2012 development introduction part 2/3
Microsoft dynamics ax 2012 development introduction part 2/3Microsoft dynamics ax 2012 development introduction part 2/3
Microsoft dynamics ax 2012 development introduction part 2/3
Ali Raza Zaidi
 
Integration with dynamics ax 2012
Integration with dynamics ax 2012Integration with dynamics ax 2012
Integration with dynamics ax 2012
Ali Raza Zaidi
 
AX 2012 R3 Installation Guide
AX 2012 R3 Installation GuideAX 2012 R3 Installation Guide
AX 2012 R3 Installation Guide
Biswanath Dey
 
Task recorder control
Task recorder controlTask recorder control
Task recorder control
Ali Raza Zaidi
 
An Introduction to the Dynamics AX Application Integration Framework
An Introduction to the Dynamics AX Application Integration FrameworkAn Introduction to the Dynamics AX Application Integration Framework
An Introduction to the Dynamics AX Application Integration Framework
Folio3-Dynamics-Services
 
AX 2012 Functional Track - Steven Hermans
AX 2012 Functional Track - Steven HermansAX 2012 Functional Track - Steven Hermans
AX 2012 Functional Track - Steven Hermans
dynamicscom
 
MB6-890 Transcript.PDF
MB6-890 Transcript.PDFMB6-890 Transcript.PDF
MB6-890 Transcript.PDF
Randy King
 
Dynamics ax performance tuning
Dynamics ax performance tuningDynamics ax performance tuning
Dynamics ax performance tuning
OutsourceAX
 
Mule Microsoft Dynamics AX 2012 Connector
Mule Microsoft Dynamics AX 2012 ConnectorMule Microsoft Dynamics AX 2012 Connector
Mule Microsoft Dynamics AX 2012 Connector
Ankush Sharma
 
Deploying customizations across microsoft dynamics ax 2012 environments ax2012
Deploying customizations across microsoft dynamics ax 2012 environments ax2012Deploying customizations across microsoft dynamics ax 2012 environments ax2012
Deploying customizations across microsoft dynamics ax 2012 environments ax2012
Prathamesh Joshi
 
Whomovedmycheese
WhomovedmycheeseWhomovedmycheese
Whomovedmycheese
Ali Raza Zaidi
 
Dynamics Day '11 - Manufacturing and Distribution Roundtable Discussion
Dynamics Day '11 - Manufacturing and Distribution Roundtable DiscussionDynamics Day '11 - Manufacturing and Distribution Roundtable Discussion
Dynamics Day '11 - Manufacturing and Distribution Roundtable Discussion
Intergen
 
Microsoft Dynamics AX 2012 - Development Introduction Training - Part 3/3
Microsoft Dynamics AX 2012 - Development Introduction Training - Part 3/3Microsoft Dynamics AX 2012 - Development Introduction Training - Part 3/3
Microsoft Dynamics AX 2012 - Development Introduction Training - Part 3/3
Fabio Filardi
 
AX 2012: All About Lookups!
AX 2012: All About Lookups!AX 2012: All About Lookups!
AX 2012: All About Lookups!
MAnasKhan
 
Microsoft Dynamics AX 2012 - Development Introduction Training - Part 2/3
Microsoft Dynamics AX 2012 - Development Introduction Training - Part 2/3Microsoft Dynamics AX 2012 - Development Introduction Training - Part 2/3
Microsoft Dynamics AX 2012 - Development Introduction Training - Part 2/3
Fabio Filardi
 
Microsoft dynamics ax 2012 development introduction part 2/3
Microsoft dynamics ax 2012 development introduction part 2/3Microsoft dynamics ax 2012 development introduction part 2/3
Microsoft dynamics ax 2012 development introduction part 2/3
Ali Raza Zaidi
 
Integration with dynamics ax 2012
Integration with dynamics ax 2012Integration with dynamics ax 2012
Integration with dynamics ax 2012
Ali Raza Zaidi
 
AX 2012 R3 Installation Guide
AX 2012 R3 Installation GuideAX 2012 R3 Installation Guide
AX 2012 R3 Installation Guide
Biswanath Dey
 
An Introduction to the Dynamics AX Application Integration Framework
An Introduction to the Dynamics AX Application Integration FrameworkAn Introduction to the Dynamics AX Application Integration Framework
An Introduction to the Dynamics AX Application Integration Framework
Folio3-Dynamics-Services
 
AX 2012 Functional Track - Steven Hermans
AX 2012 Functional Track - Steven HermansAX 2012 Functional Track - Steven Hermans
AX 2012 Functional Track - Steven Hermans
dynamicscom
 
MB6-890 Transcript.PDF
MB6-890 Transcript.PDFMB6-890 Transcript.PDF
MB6-890 Transcript.PDF
Randy King
 
Dynamics ax performance tuning
Dynamics ax performance tuningDynamics ax performance tuning
Dynamics ax performance tuning
OutsourceAX
 
Mule Microsoft Dynamics AX 2012 Connector
Mule Microsoft Dynamics AX 2012 ConnectorMule Microsoft Dynamics AX 2012 Connector
Mule Microsoft Dynamics AX 2012 Connector
Ankush Sharma
 
Deploying customizations across microsoft dynamics ax 2012 environments ax2012
Deploying customizations across microsoft dynamics ax 2012 environments ax2012Deploying customizations across microsoft dynamics ax 2012 environments ax2012
Deploying customizations across microsoft dynamics ax 2012 environments ax2012
Prathamesh Joshi
 
Dynamics Day '11 - Manufacturing and Distribution Roundtable Discussion
Dynamics Day '11 - Manufacturing and Distribution Roundtable DiscussionDynamics Day '11 - Manufacturing and Distribution Roundtable Discussion
Dynamics Day '11 - Manufacturing and Distribution Roundtable Discussion
Intergen
 
Ad

Similar to Ax 2012 x++ code best practices (20)

Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldBack-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real World
David McCarter
 
Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldBack-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real World
David McCarter
 
Bb Tequila Coding Style (Draft)
Bb Tequila Coding Style (Draft)Bb Tequila Coding Style (Draft)
Bb Tequila Coding Style (Draft)
Siwawong Wuttipongprasert
 
Automation tips
Automation tipsAutomation tips
Automation tips
Ritu Mangla
 
So You Want to Write an Exporter
So You Want to Write an ExporterSo You Want to Write an Exporter
So You Want to Write an Exporter
Brian Brazil
 
Best practices in enterprise applications
Best practices in enterprise applicationsBest practices in enterprise applications
Best practices in enterprise applications
Chandra Sekhar Saripaka
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
dwm042
 
Best Practices of Software Development
Best Practices of Software DevelopmentBest Practices of Software Development
Best Practices of Software Development
Folio3 Software
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handling
Suite Solutions
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
sachindane
 
Automation frameworks
Automation frameworksAutomation frameworks
Automation frameworks
Vishwanath KC
 
ASP.NET 05 - Exception Handling And Validation Controls
ASP.NET 05 - Exception Handling And Validation ControlsASP.NET 05 - Exception Handling And Validation Controls
ASP.NET 05 - Exception Handling And Validation Controls
Randy Connolly
 
Code Metrics
Code MetricsCode Metrics
Code Metrics
Attila Bertók
 
C++ Programming Class Creation Program Assignment Instructions
C++ Programming Class Creation Program Assignment InstructionsC++ Programming Class Creation Program Assignment Instructions
C++ Programming Class Creation Program Assignment Instructions
TawnaDelatorrejs
 
Html & CSS - Best practices 2-hour-workshop
Html & CSS - Best practices 2-hour-workshopHtml & CSS - Best practices 2-hour-workshop
Html & CSS - Best practices 2-hour-workshop
Vero Rebagliatte
 
Code review
Code reviewCode review
Code review
Abhishek Sur
 
Coding standard
Coding standardCoding standard
Coding standard
Shwetketu Rastogi
 
learnpythondjangochapteroneintroduction.pptx
learnpythondjangochapteroneintroduction.pptxlearnpythondjangochapteroneintroduction.pptx
learnpythondjangochapteroneintroduction.pptx
bestboybulshaawi
 
Back-2-Basics: .NET Coding Standards For The Real World (2011)
Back-2-Basics: .NET Coding Standards For The Real World (2011)Back-2-Basics: .NET Coding Standards For The Real World (2011)
Back-2-Basics: .NET Coding Standards For The Real World (2011)
David McCarter
 
Programming style guideline very good
Programming style guideline very goodProgramming style guideline very good
Programming style guideline very good
Dang Hop
 
Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldBack-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real World
David McCarter
 
Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldBack-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real World
David McCarter
 
So You Want to Write an Exporter
So You Want to Write an ExporterSo You Want to Write an Exporter
So You Want to Write an Exporter
Brian Brazil
 
Best practices in enterprise applications
Best practices in enterprise applicationsBest practices in enterprise applications
Best practices in enterprise applications
Chandra Sekhar Saripaka
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
dwm042
 
Best Practices of Software Development
Best Practices of Software DevelopmentBest Practices of Software Development
Best Practices of Software Development
Folio3 Software
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handling
Suite Solutions
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
sachindane
 
Automation frameworks
Automation frameworksAutomation frameworks
Automation frameworks
Vishwanath KC
 
ASP.NET 05 - Exception Handling And Validation Controls
ASP.NET 05 - Exception Handling And Validation ControlsASP.NET 05 - Exception Handling And Validation Controls
ASP.NET 05 - Exception Handling And Validation Controls
Randy Connolly
 
C++ Programming Class Creation Program Assignment Instructions
C++ Programming Class Creation Program Assignment InstructionsC++ Programming Class Creation Program Assignment Instructions
C++ Programming Class Creation Program Assignment Instructions
TawnaDelatorrejs
 
Html & CSS - Best practices 2-hour-workshop
Html & CSS - Best practices 2-hour-workshopHtml & CSS - Best practices 2-hour-workshop
Html & CSS - Best practices 2-hour-workshop
Vero Rebagliatte
 
learnpythondjangochapteroneintroduction.pptx
learnpythondjangochapteroneintroduction.pptxlearnpythondjangochapteroneintroduction.pptx
learnpythondjangochapteroneintroduction.pptx
bestboybulshaawi
 
Back-2-Basics: .NET Coding Standards For The Real World (2011)
Back-2-Basics: .NET Coding Standards For The Real World (2011)Back-2-Basics: .NET Coding Standards For The Real World (2011)
Back-2-Basics: .NET Coding Standards For The Real World (2011)
David McCarter
 
Programming style guideline very good
Programming style guideline very goodProgramming style guideline very good
Programming style guideline very good
Dang Hop
 
Ad

Recently uploaded (20)

#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 

Ax 2012 x++ code best practices

  • 1. AX 2012 X++ Code Best Practices Best practice is a method or technique that has consistently shown results superior to those achieved with other means, and that is used as a benchmark. In addition, a "best" practice can evolve to become better as improvements are discovered. Best practice is considered by some as a business buzzword, used to describe the process of developing and following a standard way of doing things that multiple organizations can use. Best practices are used to maintain quality as an alternative to mandatory legislated standards and can be based on self-assessment or benchmarking.
  • 2. AX 2012 X++ Code Best Practices Index Select Statements Comments Extra Semicolon Constants User interface labels System Oriented Constants Dates Try catch Block Transactions Conditional Statements XML Documentation Avoiding Potential Security Issues Other Best Practices References
  • 3. AX 2012 X++ Code Best Practices Select Statements ➔ The index, order by, and where statements are indented once relative to the select or while select statements. ➔ The where expression is structured in a column. ➔ The Boolean operators (&&) are at the beginning of the line (and in columns). ➔ The while select block has braces even though it contains only one statement. ➔ The braces are at the same column position as the while block. ➔ The uppercase- and lowercase-name standards are adhered to. Comments ➔ To find comments in the source (both // .. and /* .. */), use the Find dialog to search for methods containing the text (regular expression): /[/*] ➔ Comments should not include: ◆ Dates ◆ Names ◆ Aliases ◆ Version or layer references ◆ Bug numbers – unless it is a workaround, or unless the code could appear inappropriate if you didn't know that it was for a bug fix. ◆ Politically or culturally sensitive phrases ➔ If you put a comment at the start of the method to describe its purpose and use, you can use block comments (/* */) Extra Semicolon ➔ From Microsoft Dynamics AX 2012 onward, you are no longer required to put a semicolon on an empty line after the last variable declaration. Adding the semicolon is no longer an X++ best practices.
  • 4. AX 2012 X++ Code Best Practices Constants Use Intrinsic functions whenever possible. Intrinsic functions are metadata assertion functions. They take arguments that represent entities in the Application Object Tree (AOT), and validate these arguments at compile time details ➔ User interface labels this must be complete sentences. Do not build sentences using more than one label, or other constants or variables under program control (do not use concatenation). Description description = "@SYS12345" Use strFmt to format user interface text. ➔ System Oriented Constants Do not use labels. You will get a warning if a label is used inside single quotes. Dates ➔ Use only strongly typed (date) fields, variables, and controls (do not use str or int). ➔ Use Auto settings in date formatting properties. ➔ Use DateTimeUtil::getSystemDateTime instead of systemDateGet or today ➔ Avoid using date2str for performing date conversions. ➔ Most application logic should use the system function systemDateGet , which holds the logic business date of the system (this can be set from the status bar). ➔ The system function today() should be used only where the actual machine date is needed ➔ use strFmt or date2Str with -1 in all the formatting parameters. This ensures that the date is formatted in the way that the user has specified in Regional Settings
  • 5. AX 2012 X++ Code Best Practices Try catch Block ➔ Always create a try/catch deadlock/retry loop around database transactions that might lead to deadlocks. ➔ Whenever you have a retry, all the transient variables must be set back to the value they had just before the try. The persistent variables (that is, the database and the Infolog) are set back automatically by the throw that leads to the catch/retry try { this.createJournal(); this.printPosted(); } catch (Exception::Deadlock) { this.removeJournalFromList(); retry; } ➔ The throw statement automatically initiates a ttsAbort, which is a database transaction rollback. ➔ The throw statement should be used only if a piece of code cannot do what it is expected to do. The throw statement should not be used for more ordinary program flow control. Transactions ➔ ttsBegin and ttsCommit must always be used in a clear and well-balanced manner. Balanced ttsBegin and ttsCommit statements are the following: ◆ Always in the same method. ◆ Always on the same level in the code. ➔ Avoid making only one of them conditional. ➔ Use throw, if a transaction cannot be completed. ➔ Do not use ttsAbort; use throw instead. Conditional Statements ➔ If you have an if...else construction, then use positive logic:
  • 6. AX 2012 X++ Code Best Practices Avoid: if (!false) { ... } XML Documentation The following table lists the best practices error messages and how to fix the errors. Message Message type How to fix the error or warning Tag '%1' in XML documentation is not supported. Warning Add XML documentation. For information about how to add XML documentation, see How to: Add XML Documentation to X++ Source Code. Because this is a warning instead of an error, this is optional. Unsupported tag '%1' in XML documentation. Error or Warning Check the casing of the XML tags if this is reported as an error. If this is reported as a warning, an unsupported tag is present. Remove unsupported tags. Missing tag '<param name="%1">' in XML documentation. Error Add <param> tags to the XML header template. The <param> tag must have a name attribute. The value of the attribute is case-sensitive and must match the casing in the method. Missing tag 'returns' in XML documentation. Error Add <returns> tags to the XML header template. Missing tag 'summary' in XML documentation. Error Add <summary> tags to the XML header template. Tag '%1' exists more than once in XML documentation. Error Delete extra tags. This applies only when multiple tags are not appropriate.
  • 7. AX 2012 X++ Code Best Practices Tag '<param name="%1">' has no content in XML documentation. Error Add a description of the parameter between the <param> tags. Tag '<param name="%1">' in XML documentation doesn't match actual implementation. Error Fix the value of the name attribute. It is case-sensitive and must match the casing in the method. Tag 'exception' has no content in XML documentation. Error Add a description of the exception between the <exception> tags. Tag 'permission' has no content in XML documentation. Error Add a description of the required permission between the <permission> tags. Tag 'remarks' has no content in XML documentation. Error Add content between the <remarks> tags or delete the <remarks> tags. Tag 'returns' has no content in XML documentation. Error Add a description of the return value between the <returns> tags. Tag 'returns' in XML documentation doesn't match actual implementation. Error Delete the <returns> tags and the description of the return value. Tag 'summary' has no content in XML documentation. Error Add a topic summary between the <summary> tags. XML documentation is not well-formed. Error Make sure that there are no mistakes in the XML tags. Each opening tag must have a corresponding closing tag.
  • 8. AX 2012 X++ Code Best Practices Tag 'seealso' has no content in XML documentation. Error Add content between the <seealso> tags or delete the <seealso> tags. No XML documentation for this method. Error XML documentation has not been written for this method.
  • 9. AX 2012 X++ Code Best Practices Avoiding Potential Security Issues ➔ Certain APIs that ship with Microsoft Dynamics AX use Code Access Security. When these APIs are run on the server, a class derived from CodeAccessPermission must be used. This helps make the APIs more secure. ➔ When you upgrade from a previous version of Microsoft Dynamics AX, you must modify calls to these APIs to ensure that the code executes correctly. details Other Best Practices Best practice checks help to make sure that the best practice guidelines are followed. Use the Best practice parameters form to select which best practice checks to verify. Read more best practice parameters References ● http://msdn.microsoft.com/en-us/library/aa855488.aspx