Posts

Showing posts with the label Dynamics AX

Regular expressions in Dynamics AX

Image
In all versions of Dynamics AX, the Find window supports regular expressions. Recently I discovered that even the label editor supports regular expressions. Using regular expressions in the find window and the label editor can significantly reduce your search times and you can narrow down your search to exactly what you are searching for. Let us look at some example. Suppose I want to search for all classes which have methods which are named like the following, enable(Any text here)Buttons. So all names like enableActivityButtons, enableDisableButtons, enableAllButtons etc should be found. So, we first need to analyze our expression requirement. Our search string should start with enable . For that, we need to enter <enable . The < character matches the specified string at the start of the string. Similiarly, for matching Buttons at the end of the string, we need to specify Button> . The > character matches the specified string before it at the end of the ...

The field with ID '0' does not exist in table - Cause and resolution.

Image
Hello readers, In Dynamics AX coding, you should have come across this error sometime - The field with ID '0' does not exist in table 'SomeTable' So what causes this error and what is the possible resolution to it? Well, the most likely cause for this error is a missing mapping in a table map. Let us look at an example. I've a simple Map named CustVendAccount with one Account field. I've created two mappings - one with CustTable's AccountNum field and for the otehr mapping, I just specify VendTable but no field. This is how my map looks like, Now, I've a simple job which just passes either CustTable or VendTable as an argument and then we print the Account field in the map. static void CustVendAccountMap(Args _args) { CustTable custTable; VendTable vendTable; void readMap(CustVendAccount _custVendAccount) { info(strFmt("Value from table %1 is %2",tableId2name(_custVendAccount.TableId), _custV...

Problem caused by using keyword as object name in Dynamics AX

Hello Readers, When creating objects in Dynamics AX, it is advisable to use names which are not any keywords in Dynamics AX. Otherwise, you can end up with unexpected behavior. A list of all keywords in Dynamics AX 2012 can be found here . I discovered one such issue in standrd Dynamics AX. Take a look at the table InventBuyerGroup. It has two fields named Group & Description. Now suppose if I want to select the field Group from the table using a select statement, how will I do it? InventBuyerGroup inventBuyerGroup; select group from inventBuyerGroup; Simple, So what is the catch you may ask? Well, the above statement will not compile and give an error . That is because the field name group is also a keyword in Dynamics AX. So, the compiler gets confused and cant understand that it is the field name that we are trying to refer here. I'm not aware of any way of getting this work. Of course, there are workarounds like using a map but is that really needed? We ca...

New number sequence not visible in Dynamics AX 2012. How to fix it?

Hello readers, In Dynamics AX 4.0 and Dynamics AX 2009, if you created a new number sequence reference, you would restart the AOS to see the new number sequence reference in the parameters form of your module. That was all you had to do to get the new reference reflected. Try the same in Dynamics AX 2012 and you will be pleasantly suprised(or maybe bewildered) to not find the number sequence reference showing in the parameters form. This is because the numberSequence tables are no longer populated when you restart the AOS. This was an additional task that was done in Dynamics AX 4.0 and Dynamics AX 2009 everytime you restarted the AOS. In Dynamics AX 2012, the number sequence tables are populated when you select the appropriate task in the initialization checklist. So, how do we work around this issue? Simple. Just call the load() method on your module's number sequence class. For example, suppose I've added a new number sequence to the Sales and Marketing module(CR...

Futures class in Dynamics AX

Image
In Dynamics AX, if you want to find a date in a period, chances are you would be using the DateTimeUtil class. Say, I want to find the date 3 months exactly from today. Assuming a month is of 30 days, I can call the DateTimeUtil::addDays() method. So my code to get that will be, print DateTimeUtil::date(DateTimeUtil::addDays (DateTimeUtil::utcNow(), 3 * 30)); There is another application class in Dynamics AX, which does exactly this. This is the Futures class. Let us see this class in action. static void FuturesClass(Args _args) { Futures future; int i; // Setup a future class object with 365 days as a period future = new Futures(systemDateGet(), 365, PeriodUnit::Day); future.next(); info(strFmt("Future date after 3 months from today is %1",future.transDate())); // Setup a future class object with 1 year as a period future = new Futures(systemDateGet(), 1, PeriodUnit::Year); f...

How to refer to form controls in code without setting the AutoDeclaration property in Dynamics AX?

Hello readers, On a Dynamics AX form, if you want to refer to a particular control in code, the surest way you would take is to set the AutoDeclaration property to Yes. This will let you refer the control in code. There is nothing wrong with this approach and it is quite common in standard Dynamics AX codebase. But in some cases, it is preferred not to use this approach. So what is this case? Consider a scenario where you are customizing a standard form. You want to disable a particular field based on a field value. To achieve this, - You will set the AutoDeclaration property of the control to Yes - In the active method of the datasource, you will disable the control based on a condition. Now, the active() method's modification can be easily seen in the AOT but the change in property isn't readily noticed unless you perform a layer compare. Normally, in cuztomization it is a best practise to add customization tags to show what part is customized code and what is...

What is the parmLastActivatedForm method used for in Dynamics AX?

Image
Hello readers, In my earlier post, we had seen how to get all of a form's callers in Dynamics AX . One of my readers brought up a very good and interesting question around this. Some action forms opened like the Document handling form will not show the caller. Is there a way to find the caller for these forms? This is indeed correct. If you open the document handling form from any form, and look for the caller name, it will be empty. See the below image to understand what I mean. Well, this shouldn't stop us Dynamics AX developers from getting our way. In this post we will learn how to get the caller in such scenarios. The answer lies in a method in the Info class - parmLastActivatedForm() Basically, the parmLastActivatedForm() method returns the last form that was activated. So let us see all this in action. My code is in Dynamics AX 2012, but you can easily apply it in Dynamics AX 2009 as well. Let us modify the init() method of the DocuView form. This is...

How to get Form's caller in Dynamics AX?

Image
Hello readers, In Dynamics AX, when we need to find the parent of a form, we call the caller() method on the args object of the formRun object of the form. The syntax is, FormRun callerForm = element.args().caller(); In the same way, we can find the parent of the caller form as well. Something like, FormRun callerForm = element.args().caller().args().caller(); Try that and Dynamics AX will throw an error that " The variable is not of the type CLASS. " We can call only upto the 3rd method after which the AX compiler fails to return an object. We will have to first store the args() object in a seperate variable and then call the caller() method. Let us look at an example of getting all the ancestors for a form. I've a simple form, with just two methods - init() and parmFormName() Declare a variable formName of type Name in the classDeclaration. public Name parmFormName(Name _formName = formName) { formName = _formName; return formName; ...

How to remove enum values from dialogs in Dynamics AX?

Hello readers, A common requirement which I have come across from time to time is the ability to hide certain enum elements on a form. There has been various solutions to the problem. The easiest one I saw was where the developer had created two enums, one with all the values and another one with the unwanted elements dropped. This approach has many problems as comparing the enum values in code isn't possible. In Dynamics AX 2009, the SysFormEnumComboBox class was provided to solve this issue. You pass it the combo box control's id, the enum to be used and a set of allowed values that need to be shown and it works as a charm. This approach can be used effortlessly on forms. Recently, I was posed if this can be done on a dialog. Well, its not as simple to use this on a dialog but I have another solution for the problem. Let us see this in more detail here. I've a very simple dialog with just the SysDimension enum showing up. The requirement is to remove the Purpose ...

Cumulative Update pack 1 for Microsoft Dynamics AX 2012 released

Just days after the general availability of Microsoft Dynamics AX 2012, a cumulative update pack has been released for Microsoft Dynamics AX 2012. This pack contains close to 80 fixes to various bugs. You can download the pack and read more about the fixes in the pack here . Note: PartnerSource credentials required.

How to add or delete a label file in Dynamics AX 2012

Image
By now, you all must be aware that we are done with AOD files in Dynamics AX 2012. Model is the new deployment option for deploying AX objects on various installations. If you want to learn more about models, MFP has an excellent three part series on it which you can read here . In this post we will look at how label files are contained within models in Dynamics AX 2012. We now have a new node in AOT - Label Files All labels in the system are grouped under this node. Now suppose we have a label from another installation which we want to bring in to our system. Right click on the Label Files node and select Create from File . Browse and selct your .ald file. Once you select the file and hit OK, a new node is added under the Label Files node corresponding to the label file imported. You will get an info message saying " Imported label file:C:\Users\Administrator\Desktop\MyLabelen-us.ald " In AX 2009, after placing a label file, we needed to restart the AOS so that the...

How to show or hide query ranges on dialogs in Dynamics AX?

Image
Sometimes, we create dialogs which have a query associated with them. We use this query to filter records and show us some data. Often, associating such queries with dialogs adds ranges to the dialogs. But do we really need these ranges always? In this post, let us look at one of the reason why ranges may get added and how to hide them. Let us create a simple Query as shown in the figure below. Nothing fancy about it. Just SalesTable and SalesLine joined. Now we will create a dialog, set the dialog's query with the query we created above and run it. When the dialog opens, this is how it looks. Notice now that there are two SalesId ranges. These come from SalesTable and SalesLine respectively. The logic to add the range here is that the first active index on the tables are displayed. Take a look at both SalesTable and SalesLine. On SalesTable, the first index is SalesIdx and on SalesLine, the first index is SalesLineIdx. Before we move further, some of you may question...

How table and class customizations are stored in UtilElements?

Image
In my previous article on finding all the layers on which an object has been modified, I explained how the UtilElements system table can be used for this. You can read that post here . Some of my readers mailed me asking that they were not getting the correct results when querying the UtilElements table. I clarified what the issue could be. This post will discuss further on the UtilElements table and what are the things one need to be aware of when querying this table. Let us first see how table customizations are stored in the UtilElements table. Let us take the Address table as an example. On my system, I have just added a comment in the axAddress() method. As you can see in the below image, the table is shown as existing on the usr layer and you can also see the actual changes. Now I'll query the UtilElements table where name is Address. while select utilLevel from utilElements where utilElements.name == tableStr(Address) && utilElemen...

How to toggle button states using the FormButtonManager class in Microsoft Dynamics AX 2009?

Generally in Dynamics AX, we write seperate methods for controlling the state of buttons on forms and call these from the data source's active method. In Dynamics AX 2009, a new framework was introduced for this need. This is the FormButtonManager class. This class provides all the necessary methods to tap into this framework and control the state of the buttons. The idea is similiar to what we are used to do but this class provides a more clean approach. Let us take a practical approach to using this framework. We will work on the Customers form (CustTable). On the Customers form, we have a menu button named "Project Control". Now the requirement is that this button should be enabled only for customer's who are associated with projects. Now we need a provider class to provide us with the various rules which control the button states. For this purpose we will have to create a class. Each rule is created as a method in the class which returns a boolean value represen...

Quick tip: How to find your security identifier(SID) on your system?

Whenever we restore our Dynamics AX database, we have to update the UserInfo table to set the correct NetworkDomain, NetworkAlias and the SID fields. Most of us have a simple SQL script which we run whenever we need this. You may know the network domain and alias values but finding the SID value can be difficult. Well, the SID value or Security IDentifier value is a unique ID by which your system is identifier by other systems or network domains. This value is stored in the registry. Open the Windows registry by typing regedit in the run menu and navigate your way to HKEY_CURRENT_USER\Software\Microsoft\Protected Storage System Provider\S-X-X-XX-XXXXXXXXX- XXXXXXXXXX- XXXXXXXXXX-XXX This is where you can find the SID of your system. Hope this helps.

How to get a list of all the layers on which customization has been made?

Image
In Dynamics AX 4.0 & 2009, all layer customizations are stored in AOD files. In Dynamics AX 2012, the AOD files have been replaced by SQL model data store. Sometimes, a developer may want to know what all layers a particular object has been customized on? For this, there are two possible solutions available. Querying UtilElements table Using TreeNode class The UtilElements system table can be considered a representation of the AOD file in a table format. We can query any kind of information like, which layer an object has been customized, what has been customized, the source code for an object on a particular layer, the number of times an object has been saved, who created or updated the object etc. The advantage of using UtilElements is that it is extremely fast. The second approach is using the TreeNode class. The method applObjectLayerMask() returns an integer whose value is a bitwise representation of all the layers on which the object has been customized. Let us look at t...

How to set focus on a control on a form that has been opened through code?

The other day, a question came up if we can open a form through code and focus on a particular control? Well, we surely can easily do that. The setFocus() method is commonly used to put the focus on any control. The question was to put focus on a control on a form which was open through code. The solution is to first get a reference of the control on which you want to set the focus and then call setFocus on it. The FormDesign class has a method controlName() which will return us the control. It takes a string argument. The below code shows us how to do what we just discussed. static void setFocus(Args _args) { Args args; FormRun formRun; FormControl formControl; ; args = new Args(formStr(Address)); formRun = classFactory.formRunClass(args); formRun.run(); formRun.detach(); // Get a reference of the control we want to set focus on formControl = formRun.design().controlName(identifierStr(Description_Name)); formControl.setF...

Employee self services feature demo in Microsoft Dynamics AX 2012

The Employee self services portal in Microsoft Dynamics AX 2012 is the centralized location for all employees of the organization to go about performing common tasks. Employees can order products, submit their expenses, approve expense reports & other documents or navigate and submit their timesheets. There is a video available on this here Go check it out and share your thoughts.

Dynamics AX 2012 Pricing and Licencing information

The Dynamics AX 2012 Pricing and Licencing information in draft format is now available on partner source here (Partnersource credentials required)

Microsoft Dynamics AX 2012 global virtual launch event

The Microsoft Dynamics AX 2012 global virtual launch event is scheduled for Thursday, September 8th. The event is a global platform for Microsoft executives, customers and partners to come together and speak, listen, give product demos and watch product tours specific to business or industry. You can find more details and the registration link here