AX Developer Tips for Newbies: Part 2

by | Updated November 2, 2020 | Development, Dynamics AX

In a previous post I compiled a collection of tips gleaned from teaching AX developers in my training classes. The selections included in AX Developer Tips: Part 2 are  dedicated to X++ coding tips.

Read more on AX Developer Tips for Newbies: Part I here. 


Select statements

A. It is highly recommended to use a field list in your Select statements if you do not need access to all fields in the table. Just remember, only the fields in the list will contain values. If you try using another field later in your code, you will get unexpected results.

B.  Similarly, the exists/notexists join returns no data at all. In the following statement, the custInvoiceJour record buffer will contain no data.


For this reason, it is not possible to join another table using custInvoiceJour. This won’t work. The custTrans buffer will be empty.


Where Clause and Indexes

When issuing select statements against tables in X++ code, align the where clauses in the X++ select statements to the fields that are contained within an existing index. If this is not possible, then consider adding an index to the table that matches the where clause. Where statements that do not align with indexes can cause table scans which lead to significant performance problems when the tables have a large number of records in them. This is especially true when selecting records from transactional tables.

Avoid statements like the following where the LedgerJournalTrans table does not have an index that contains the AcknowledgementDate in it.




In select statements use the keyword firstonly to retrieve the first record found in the database table when verifying that a condition is true or false. For example when verifying if a given sales order contain any sales lines, firstonly can be used because once the first sales line is found the condition is true. Also use firstonly when the developer knows that only one record will be found in the table. By using the keyword the search through the database is completed as soon as the first record is identified.


Replace this code:



Transactions and Locking

A.  When there are ttsbegin and ttscommit statements nested within other ttsbegin and ttscommit statements, locks held on records in the table are not released until the outer ttscommit is reached, so keep the number of lines of code between the ttsbegin and ttscommit as small as possible. Additionally since the locks are not released until the ttscommit is reached avoid any tts statements that wrap dialogs requiring user intervention.

B. In the following code locks are initiated in both of the update statements. Those locks are not released until the final/outer ttscommit statement is reached:


Table Methods

Before writing a lot of code to access or update base tables in AX, take a look at the methods on the table you are interested in. Most tables in AX have built-in methods you can use to perform basic tasks like finding and initializing records.


Find method – find a record by the primary key


InitFrom methods -Initialize fields in the table from another table




Before anything else, do yourself a favor and update the AOT cross-reference in your development environment. The cross-reference system allows you to see the relationships between objects. It is most useful for finding where EDT’s, fields or methods are used in AX. When you are learning, it is an invaluable tool for quickly finding code examples in the base product and also ensures that you adhere to standard coding practices.

Yes, the update takes a long time to run. Try running it from a Job instead of from the Tools menu. Here is a sample job. Start it up at the end of your work day and it will be finished by the next morning.


Once the job is complete, you will have the Used By option as below:

AX Dev Tips


We can find out how the ChooseLines method is used and from where:

Choose Line Method in AX


Best Practices Compiler

Set the Compiler to Level 4 when you are writing new code. AX will point out Best Practice deviations at compile time.

Best Practice Compiler


Under Tools, Options, Development Tab, select Best Practices. Here you can set the checks that you want to perform.

Best Practices in Dynamics AX



Related Posts

  • I have compiled a collection of tips that seem to help new AX developers in my training classes, so I thought it would be good to share with the public.…

  • Over on the AX Support site on MSDN, Daniel Durrer has taken the time to keep tabs on the latest builds for Microsoft Dynamics AX 4.0, 2009 and 2012.  I…

  • TFS can be a wonderful tool for the Dynamics AX Developer to help track bugs, tasks, etc. If it is used correctly, it can greatly increase your productivity. To learn…



  1. AX Developer Tips for Newbies: Part 1 | Stoneridge Software Inc - […] Read more on X++ coding tips in AX Developer Tips for Newbies: Part 2 […]

Submit a Comment

Your email address will not be published. Required fields are marked *

Upcoming Events


01sep10:00 am10:30 amEnsuring Quality and Compliance for Batch Manufacturers in Life Sciences

01sep12:00 pm12:30 pmIs it Worth It to Move to the Cloud? A Look at Considerations for Current Agribusinesses Using Dynamics GP

01sep2:00 pm2:45 pmWhat’s New in Dynamics 365 Finance and Supply Chain

09sep11:00 am12:00 pmConfab Live with Stoneridge – Data Strategy and Reporting – Mining Decision Making Insights

15sep10:00 am11:00 amSolving the Biggest Challenges in Agribusiness Through Innovation and Technology

22sep12:00 am12:30 pmSimplifying Payroll and HR Management with ADP Workforce Now

22sep10:00 am10:30 amStreamlining Batch Manufacturing with Technology

22sep2:00 pm2:30 pmProcess Automation for Microsoft Dynamics D365 for Business Central, Finance and Operations and GP

23sep11:00 am12:00 pmConfab LIVE with Stoneridge - Riding the Wave 2 Release – Key Features Coming to Dynamics 365 this October

29sep10:00 am11:00 amTop Five Reasons Why NOW is the Right Time to Move from Salesforce to Dynamics 365 Customer Engagement

29sep12:00 pm12:45 pmUnderstanding Job Costing and Tax Management in Business Central

29sep2:00 pm3:00 pmDigitalizing Horticulture & Agriculture - How to Sell Plants Online and Simplify Business Management

30sep12:00 pm4:00 pmSecurity and Permissions Training for D365 Business Central or Dynamics NAV


06oct10:00 am10:30 amPreview of D365 Business Central Fall Release Features and Functionality

06oct12:00 pm12:30 pmInsider's Guide to New Features Available in the Fall Release of D365 Finance and Supply Chain

07oct11:00 am12:00 pmConfab LIVE with Stoneridge - Dataverse and Dynamics in Review – Let’s Get Technical

21oct11:00 am12:00 pmConfab LIVE with Stoneridge - Dataverse and Dynamics in Review – Let’s Get Functional

26oct(oct 26)9:00 am28(oct 28)5:00 pmStoneridge Connect Leadership and Community Conference

About Stoneridge
Stoneridge Software is a unique Microsoft Gold Partner, with emphasis on partner. With specialties in Microsoft Dynamics 365, Microsoft Dynamics AX, Microsoft Dynamics NAV, Microsoft Dynamics GP and Microsoft Dynamics CRM, we focus on attracting the most knowledgeable experts in the field to our team, and prioritize delivering stellar solutions with maximum impact for your business. At Stoneridge, we are deeply committed to your results. Each engagement is met with a dedicated team, ready to provide thorough, tailored, and expert service. Based in Minnesota, we intentionally “step into your shoes,” wherever you are. We focus on what you care about, and develop trusting, long-term relationships with our clients.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!