Measuring is knowing. Before you start changing code, make sure you have a set of data you can keep reusing for your tests. Measure the performance of your code on that data after each change in code so you know the impact of your changes.
One way to do this is by using the Winapi::getTickCount() or WinApiServer::getTickCount() if your code runs on server method.
Tip 2: limit the number of loops
A LOT of time goes into loops. If you have a performance problem, start looking for loops. Code can run really fast, but it can get slow when it is executed too many time, eg, in a loop.
Tip 3: avoid if in while select
When there is a if in a while select, see if you can rewrite it a a where statement in your select. Don’t be affraid use a join either. Consider the following example:
Tip 4: avoid double use of table methods
Using table methods a lot can get really slow if you do it wrong. Consider the following example:
This example code looks nice, but there’s a problem. The salesLine.inventDim() method contains the following:
This means that the invendDim record is read three times from the database. It is better to declare the inventDim record locally and only retrieve it once:
Tip 5: Don’t put too much code on tables
Code on tables is usually fast, but things can get slow if you use it to much. Say you have a table with an InventDimId field. If you have 5 methods that need the InventDim record, because you don’t have a classDeclaration method on your table, you need to call this function 5 times, once in every method:
When you put these methods on a class, you could optimise it by fetching the record only once and storing it in the classDeclaration, or better, passing it as a parameter to your methods. An other example is fetching parameters from parameter tables, eg InventParameters::find(). On a table, you have to fetch it each time you call a method. In a class, you would probably optimize your code to only fetch the parameter record once.
Tip 6: Use the fastest code
For some tasks, there is special code that is faster than the code you would normally write. For example:
The same applies to update_recordset for updating records. Also, when adding values to the end of a container
is faster than
Tip 7: Every optimization counts
Remember that every optimization you do to you code counts, even if it’s a little one. Small performance tweaks can have a huge effect once you process large quantities of data. So don’t be lazy, and optimize.
In this post let’s explore creating XML using X++ code in Dynamics AX.
The following example shows how to create and write data to an XML file by using the XmlDocument, XmlElement, and XmlWriter classes. It loops through all of the records in the CarTable and find all the fields in the table automatically by using the DictTable and DictField classes.
The file that is created looks like the one in the following screenshot(only first part of the file is shown):
As you can see, this file is based on a standard XML format with tags and values only. You can, however, use tag attributes as well. To put the values from the table into tag attributes instead of their own tags, simply change the following code snippet in the example above
With these lines:
The file that is created now looks like the one in the following screenshot:
The answer is that there is no difference, the difference is a conceptual one rather than a functional or a technical one. So I think you will make a better choice for your scenario base on functional side.
Display Menu item
This folder is used to contain menu items that reference runnable application objects that primarily present forms, ddialog and so on, to the user. May be this forms, dialog called from another forms.
Output Menu item
An output menu item application objects whose primarily function is to print a result or report.
Action Menu item
You should create a menu item under this folder if your runnable application objects whose primarily function is to do some kind of a job, such as creating or updating transactions in the database.
The model store is the portion of the Microsoft Dynamics AX database where all Microsoft Dynamics AX application elements are stored, including customization. The model store replaces the AOD (application object definition) files used in previous releases of Microsoft Dynamics AX (I mean from 4.0 to 2009).
Layer and model information are integral parts of the store. The AOS has access to the model store, handles layer-flattening, and provides model data to all the Microsoft Dynamics AX sub-systems, such as form- and report-rendering and X++ code.
Microsoft Dynamics AX contains sixteen layers. Each layer consists of one or more logical parts called models. A system generated model exists for each layer.
For example, the VAR Model is the system generated model for the VAR layer. You can use the system generated models to install and start working with the base Microsoft Dynamics AX system. You can leverage the capabilities of models, and tools and functionality that support the models, during customization of the Microsoft Dynamics AX application.
The model store is the portion of the Microsoft Dynamics AX database where all Microsoft Dynamics AX application elements are stored, including customization.
The model store replaces the AOD files used in previous releases of Microsoft Dynamics AX. It can be managed through the AXUtil command line utility, or by using Windows PowerShell.
The baseline model store database holds model store tables for the previous version of metadata. Use it only during an upgrade.
The baseline model store is similar to the old folder in previous releases of Microsoft Dynamics AX.