Microsoft Dynamics AX FAQ

Microsoft Dynamics AX FAQ

How to override the event methods on dialog controls?

X++Posted by Studio Erudit team 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:

_dialog.dialogForm().formRun().controlMethodOverload(true);

_dialog.dialogForm().formRun().controlMethodOverloadObject(this);


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

if(isFieldModified)
{
dlgFldEmplName.value(EmplTable::find(control.text()).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);
dialog.addCtrlDialogField(dlgFldEmplId.name());

dlgFldEmplId.init(dialog);
dlgFldEmplId.label("@SYS81251");
dlgFldEmplId.helpText("@SYS81251");
dlgFldEmplId.value(emplId);


}

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.

  • Comments(4)//daxfaq.studioerudit.com/#post7