Posts

Showing posts from August, 2011

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...

Dynamics AX 2012 price list

Hi readers, For all of you who were interested in knowing the cost of a Dynamics AX 2012 license, well, the wait is over. Microsoft has provided a nice little Excel sheet which can help you estimate the cost of your implementation. You just need to enter the quantity of components you wish to procure and the sheet will calculate the cost for you. You can download the sheet from here . Note: PartnerSource login required.

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...

General announcement - Change in blog layout

Dear readers, Over the couple of days, I've been working on changing the layout of the blog. I'll roll out the new layout in a couple of weeks. Don't be surprised if you come back and see a completely new color or layout. It will be the same blog and the same old me :). Thank you all.

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...