Skip to main content

Posts

Formatting real-controls i AX reports using x++ code

I was asked by a (danish) client if Dynamics AX could format amount fields according to lanaguage code of the customer. The problem arises as the danish format for amounts is: 999.999.999,99 That is thousand separators are the dot-sign and decimal separator is the comma-sign, and the english format is 999,999,999.99 That is thousand separators are the comma-sign and decimal separator is the dot-sign. Now the Ax client is able to run in several language of course, but this also imposes the regional settings on any reports printed. Thus if you run the AX client with danish language and prints an invoice for an english customer, all amounts will be printed using danish formatting. I wrote a small class that builds a list of all real-controls in a report. You can then feed it a langauge code and it will traverse the list of controls and format them accordingly. Thus we can now batch invoice customers and get invoices printed where amounts are formatted according to the language code of the...

Refreshing (executeQuery) a calling form from the called form.

A feature that you often need when you work with code that is called from a form and manipulates data, is to be able to refresh the calling form to reflect the changes made, when the code has been run. This could also be a form calling an other form, where data changes are made, in the called form, but the changes must be reflected in the calling form, when the called form is closed. I have seen it done by making call back to a method on the calling form, that does the refresh. You can however make the refresh from the CALLED form or code, using an args-object. When a form calls an other form it is typically done via a menu item, and thus automatically an args object is passed to the called form. The args object can carry a tablebuffer object that is acessed with the record method on the args object. You can determine if the tablebuffer object is a formDataSource, and if so, you can instantiate a formDataSource-object on which you call the executeQuery-metod. One example could be: Form...

Don't override the tabChange-method on a tab.

Working on a Dynmics AX 4.0, I learned today (from a wizard-level colleague), that overriding the tabChange-method on a tab in a form in Dynamic AX/Axapta, disallows the usersetup of the tab and all of it's children. My problem was that a customer complained that they were not able to make a user setup of the form and add fields to a tab and all tabpages below that tab on the PurchTable-form. The customization: public boolean tabChange(int fromTab) { boolean ok; ; ok = super(fromTab); if (ok) purchTable_ds.lastJournals(); return ok; } had been added to the tab. Seing that the method call PurchTable_ds.lastJournals(); was present in pageActivated-method on the tabpage TabHeaderPostings in the SYS-layer (!), I decided to remove the above customization.

Useful function for left trimming 0's in a string.

A colleague of mine made this little function. It strips leading 0's in a string. The string may only be a 1000 characters long, but that can be modified by changing 1000 to an other value. static TempStr strLtrim0(TempStr txt,str 1 trim = '0') { int i = strNfind(txt,trim,1,1000); return i ? subStr(txt,i,1000) : ''; }

Having a caller form close a called form

Today I was asked an interesting question by a colleague. If a form is opened from an other form, can we make Axapta (3.0) close the called form automatically when closing the caller form. I remembered some old code for making a form truly modal in Axapta, and thought that maybe we could use some of that. Now the solution presented here, is only good for one called form. but it should be quite easy to implement, that all opened forms open from a parent form, are closed when the parent form is closed, by changing the hwndchild reference to a list or a set of HWND-references, looping through that set or list, checking if each HWND-reference refers to an active window, and then and destroying each window. A small example code project can be downloaded here The project contains two small forms and a display menu item. The parent form test, has a buttongroup where the menuitem (referring to the child form testchild) is included. When you open form test, and click the button, testchild open...

Mental note to self - disabling upgrade check list

Today I experienced that the Administration menu in AX 3.0 was very limited. This was due to a previous upgrade of the Payroll module, resulting in the upgrade check list was to be run. However the upgrade had been done in a dev/test- environment and been moved to a test/live environment. Thus the need to complete the full upgrade check list was nonscence. However we couldn't deactivate the upgrade check list via the menu, because the administration menu was limited to showing the Periodic menu node only. However we could access the AOT :). Mental note to self: If you want to disable the upgrade check list but for some reasone you have no access to the Administration menu item Administration/Setup/System/Checklists/Prevent startup of list you can activate the Action menu item SysCheckList_InitNoUpdate. :) Restart the AX client, and the Administration menu should be complete :). That was what I experienced anyhow. 20\01\2010 - UPDATE Well one more thing to mention about this little ...

Batch-renaming a primary key.

For a programmer who has experienced the "terror" of having to batch-rename primary keys in Dynamics AX's predecessor XAL/C5, I was pleasantly surprised to find how easy it is in Dynamics AX 2009. Though not documented a method called renamePrimayKey exists on the kernel class xRecord which each table apparently inherits from. If you call this method after changing the primarykey field on a tablebuffer, this change will be cascaded to related tables. :0) I was given a task to perform renaming of Items in the InventTable. In an environment that is to go live - so THERE WERE NO TRANSACTIONS OG STOCK LEVELS . If this has been the case we would have adviced the customer to live with it, as the renaming process potentially would have taken a very long time Nearly 75% of the item numbers were named with 4 digits, the rest with 5. The customer wanted only 5-digit item numbers. How to do this in one go ? A simple job is enough: static void Job7(Args _args) { InventTable inven...