torsdag den 16. december 2010

Outlook WTF ?

A quick None AX-related post regarding strange software behaviour.

I was booking my wifes work in my calendar.
She works nights right now at a hospital, and I needed this in my calendar, to be able to plan in project work for my studies.
She works night shifts 7 days in a row starting tuesday evening ending monday morning the following week, and this every second week.

I tried to book this using reoccurence, and got an extreme amount of hours.

WTF? :0)

onsdag den 17. november 2010

AliasFor property on a tablefield

Ever wonder what the AliasFor property on a table field is used for ?

It is actually a pretty nifty little feature of the AX runtime.

I was tasked with making a solution for the following problem:

* Introduce a new field on the item table that can hold the EAN number of the item.
* Enable the user to be able to type in either the item id OR the EAN number when searching for an item to put on e.g. a sales order line.
* Make sure that the EAN number is shown in the look up lists

This actually quite easy to do.

First I created the EAN number field on the InventTable using a new extended datatype created for that purpose.

Then I created a new index on the InventTable containing the new field. This of course makes for searching for EAN numbers effeciently, but it also makes the EAN number field appear in the lookup list.

The final thing to do was to set the AliasFor property of the new EAN Number field to be an alias for ItemId, by assigning the value ItemId to the property.

Now "magically" the user is able to type in both item id and EAN number in the Item ID field of e.g. a sales order line, or an item journal etc. to get the item number.

So the AliasFor property can be used to enable the user to use more fields as search keys when directly typing in keys in a field.

tirsdag den 2. november 2010

Dynanics AX - WTF ?

Try the following job in Dynamics AX:

static void Job16(Args _args)
info(conPeek(new HeapCheck().createAContainer(), 4));

I've tested it in Dynamics AX 2009 and Axapta 3.0, so I guess it would work in Dynamics AX 4.0 also.

Translated from danish the result reads:

"Hi mum, heres comes a buffer"

An AX easter egg. :)

2012.11.07 - Update:
Just tried the same "fun" job in Dynamics AX 2012.
It seems that the good people at Microsoft have been reviewing some of the old kernal functions, as the result of running the above mentioned is now:

"buffer buffer buffer buffer".

torsdag den 17. juni 2010

Finding differences in code layers between installation

When working with customizations in Dynamics AX I consider it best practice to have several installations for the same customer.

At a minimum you should have a development environment, a development test environment, a test environment besides the production environment that the customer runs in daily business.

The development environment is for hacking away, developing and doing research and experiments.

The development test environment is for testing the customizations (inhouse QA) before releasing it to the customer for test.
The transfer of customizations between DEV and DEV TEST is done by exporting and
importing .xpo-files.

The TEST environment is where the customer makes acceptance test of customizations.
The transfer of code to the TEST enviroment is preferably done by copying layer (.aod)-files from the DEV TEST to the TEST, allowing for release/build control.
If successive deliveries must be done, this can be again be done by exporting importing code AS LONG AS YOU ENSURE EXPORTING AND IMPORTING IS DONE WITH ID'S AND LABELS using an outer layer.

By doing the above described, you avoid having ID-conflicts, when doing RELEASE-upgrades.
A release/buld can the be delivered by copying the .aod and label-files from the DEV TEST to the TEST, and deleting outer layers where successive test-deliveries have been made. Thus when you deliver a release/build you have all customizations rolled up in the layer you use for release.

When making a delivery to the production environment, this is preferably done by delivering layer-files. Again succesive deliveries for hotfixes can be done, by observing the above mentioned rules for the TEST environment (exporting / importing with ID'S and LABELS).

When working as a consultant you are sometimes challenged by having to take over a customer from someone else.
It can become even more challenging, if your predecessors have not been taking the above best pratice rules in to consideration, and you have doubts if the environments TEST and PRODUCTION are in synchronization.
Of course if recently deliveries have been made for test by the customer they wouldn't be.

But some times hotfixes are made directly in the production, and not carried back to the DEV and DEV TEST environments thus leaving the risk that the hotfix will be overwritten by a new release from the DEV TEST to TEST and further on from TEST to PRODUCTION.

I recently had this situation happen to me, and needed to get an overview of the differences between the layers in TEST and PRODUCTION.
Best practice was not followed in this case, so no DEV and DEV TEST enviroments were present, and hotfixes had been made directly in the production.

So I took the layers from the production environment and copied them to the appl / old folder under the TEST enviroment, and used a litte job to build a list of the differences.

Using this list, I was able to pull the code from the PRODUCTION missing in the TEST environment to the TEST environment, so that a release from the test environment weas made.

Se code below:

static void UtilElementsFindDiffInLayers(Args _args)
UtilElements newElement;
UtilElements uppElement;
UtilElementsOld oldElements;
UtilElements delElement;
UtilElementType type;
UtilEntryLevel level = UtilEntryLevel::cus;
Container types = [UtilElementType::TableInstanceMethod, UtilElementType::TableStaticMethod, UtilElementType::ClassInstanceMethod, UtilElementType::ClassStaticMethod];
UtilElementId uid = 0; //ClassNum(SysTableBrowser); // init UID if running on specific element
if running on specific element
boolean testMode = false; // TRUE to only test
Counter i;

type = conpeek(types,i);
while select newElement
order by utilLevel
where newElement.utilLevel > UtilEntryLevel::dip &&
(newElement.parentId == uid || !uid)
join oldElements
where oldElements.utilLevel == newElement.utilLevel
&& ==
&& oldElements.recordType == newElement.recordType
&& oldElements.parentId == newElement.parentId
if (oldElements.source != newElement.source)
info(strfmt("Layer: %1 Difference: %2 %3.%4",enum2str(newElement.utilLevel),global::enum2Value(oldElements.recordType),xUtilElements::parentName(newElement),;


torsdag den 6. maj 2010

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:

That is thousand separators are the dot-sign and decimal separator is the comma-sign,

and the english format is

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 customer. :0)

torsdag den 29. april 2010

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 SalesTable
has a menuitembutton that calls Form SalesLine.

Form SalesTable has a display method that sums up data manipulated in Form SalesLine.
When closing form SalesLine we need Form SalesLine to re-execute the query in Form SalesTable and thus refreshing the data form SalesTable is showing.

This can be done by overriding the close method on Form SalesLine and putting the following code into it:

public void close()
FormDataSource fds; // Form data source object
SalesTable salesTable; // tablebuffer passed in args object

// Refresh calling form data source
salesTable = element.args().record();
if (salesTable.isFormDataSource())
fds = salesTable.dataSource();
if (fds)

The above shown can also be used in a main-method on a class, so that code in the class that manipulates data shown in a form, where the class is called via a menu-button on the form.

I thought of doing it with a common object, and putting the code in a method on the GLOBAL class, to make it useable everywhere from a single line of code, but the Axapta client (3.0) kept crashing when calling common.dataSource() :0(.

mandag den 26. april 2010

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)

return ok;

had been added to the tab.

Seing that the method call


was present in
pageActivated-method on the tabpage TabHeaderPostings in the SYS-layer (!),
I decided to remove the above customization.

onsdag den 21. april 2010

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) : '';

tirsdag den 16. marts 2010

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

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

Now when you give focus to the test (parent) form, and close it, the child form will automatically close.

As always - USE AT OWN RISK.

torsdag den 14. januar 2010

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 problem. Today we encountered the problem at a customer site, but with an additional twist. The twist being that we were not able to run the menuitem from the AOT, because of insufficient rights !!!

Ouch ... then what to do ?

Well I examined the class hierachy that among other things runs the upgrade check list and found the static method


I copied the code in this method to a job (remembering the macro #SysCheckList in classdeclation of SysChecklist

static void Job10(Args _args)

SysSetupLog::saveEx(classstr(SysCheckListItem_Synchronize), ''); //Do not run Synchronize
SysSetupLog::saveEx(classstr(SysCheckListItem_SynchronizeUpgrade), ''); //same
SysSetupLog::saveEx(classstr(SysCheckList_Upgrade), #CheckListFinished); //Do not run upgrade
SysSetupLog::saveEx(classstr(SysCheckListItem_Compile), ''); //Do not run compile
SysSetupLog::saveEx(classstr(SysCheckList_Setup), #CheckListFinished); //Do not run setup

Ran that and the check upgrade list didn't start up any more :)