Blog Image

Microsoft Dynamics AX FAQ

How to find an AOT object by its property?

X++ Posted on 2008-11-06 23:28

The X++ job below shows how to find all tables in the AOT where the SaveDataPerCompany property is set to No.

static void se_findAOTObjectByProperty(Args _args)

TreeNode treeNodeTables = TreeNode::findNode(#TablesPath);
TreeNode treeNode;
str strPropertyName = ‘SaveDataPerCompany’;
str strPropertyValue = ‘No’;

// first table
treeNode = treeNodeTables.AOTfirstChild();

while (treeNode != null)
if (treeNode.AOTgetProperty(strPropertyName)== strPropertyValue)

// next table
treeNode = treeNode.AOTnextSibling();

How to get the top most layer of an AOT object?

X++ Posted on 2008-10-19 16:10

The X++ job below shows the top most layer of an AOT object (in this example it is the Address table).

static void se_topLayer(Args _args)

int i;
str strAOTObjectPath = #TablesPath + ‘\\’ + tablestr(Address);
TreeNode treeNode = TreeNode::findNode(strAOTObjectPath);
UtilEntryLevel topLayer;

for (i = 0; i <= 0xf; i++)
if (bitTest(treeNode.applObjectLayerMask(), 1 << i))
topLayer = max(topLayer, i);

print topLayer;


How to override the event methods on dialog controls?

X++ Posted on 2008-04-22 22:31

Overriding the event methods (e.g. modify, validate, selectionChange) on dialog controls is not as straight forward as it is on form controls, but the good news is that it is possible!

In order to override the event methods on dialog controls, the following needs to be done (for simplicity we assume that your class extends RunBase class) :

1) The method dialogPostRun() should be overridden and following two lines are added after the super() call:



This will allow to call the event methods of your class.

2) The actual event methods should be added.

The format of the event method name is as follows: fld<ID>_1_<event name>

Please see the example below.

This method is called whenever a value of the dialog control with ID 900 is modified. In our case it is Employee ID field.

public boolean fld900_1_modified()

FormStringControl control = dialog.formRun().controlCallingMethod();

boolean isFieldModified;

isFieldModified = control.modified();

// every time the employee id is changed, update the employee name


return isFieldModified;

You will also need to make sure that the control “Employee ID” gets the same control ID as used in the event method name (ID 900). This should be done at the time of adding the control to the dialog. Please see below:

protected Object dialog(DialogRunbase _dialog, boolean _forceOnClient)
dialog = super(_dialog, _forceOnClient);

// Add a new field by explicitly specifying the field id.
// This field id is used to create the field event methods (e.g. fld900_1_modified()).

dlgFldEmplId = new DialogField(dialog, typeid(EmplId), #dlgFlgEmplIdFieldNo);



As you can see the macro #dlgFlgEmplIdFieldNo is used to assign the ID to the dialog control. The macro is defined in the classDeclaration and it equals 900.

That’s all what you need to do to be able to override the events on the dialog controls.

Here you can download a complete class which has the code used in the examples above.