Override the event methods on dialog controls in Dynamics AX

In generally most of the Form control events (Modifying Field, Cursor movements, Focusing events, etc...) can override using standard AX method. But in dialog control events are not as straight forward as it is on form controls. Today I’m going to show how we can override Dialog controls events.

Step 1: Create a Class extends by RunBaseBatch class & declare main variables. In my example I have extended by RunBaseBatch Class.

class Test_DialogField extends RunBasebatch

{

CustAccount CustId;

DialogField dialogCustId;

DialogField dialoglName;

Dialog dialog;

#define.CurrentVersion(1)

#localmacro.CurrentList

CustId

#endmacro

}

Step 2: Add Pack() & Unpack() methods. Here I have not written code to store & retrieve stored data. But I added those methods to avoid compiling errors.

public container pack()

{

return connull();

}

public boolean unpack(container packedClass)

{

return true;

}

Step 3: Add Main() method to Execute class.

static void main(Args args)

{

Test_DialogField tmpDialogField = new Test_DialogField();

;

if (tmpDialogField.prompt())

tmpDialogField.run();

}

Step 4: The dialogPostRun() method should override like below. This will allow calling to the event methods.

public void dialogPostRun(DialogRunbase tmpdialog)

{

super(tmpdialog);

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

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

}

Step 5: Add code to display dialog fields.

protected Object dialog(DialogRunbase tmpdialog, boolean forceOnClient)

{

;

dialog = super(tmpdialog,forceOnClient);

dialogCustId = dialog.addFieldValue(typeid(CustAccount),"Customer", "Customer");

dialoglName = dialog.addFieldValue(typeid(Name),"Name", "Name");

return dialog;

}

Step 6: When we have used Dialog field in the class, that Dialog field name in the System will appear with a different format. Its look like: fld<ID>_1. This ID value can be changed according to number of dialog filed which we have used. By using following step we can get exact Field ID & system Name.

· Run the class which you created

· Right Click on the Customer field & select “Setup”

· You will get below form. I have coloured Dialog Filed System name by RED Colour. In my example System name of the Customer Dialog Field is Fld1_1.

This System Name we should use to write our “modified” method. Then it will call whenever a value of the dialog control with ID 1 is modified. In our case it is Customer ID field.

public boolean fld1_1_modified()

{

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

boolean isFieldModified;

;

isFieldModified = control.modified();

if(isFieldModified)

{

dialoglName.value(custTable::find(control.text()).Name);

}

return isFieldModified;

}

When you execute the class & select a customer Id, then above method will call & return the customer Name to other dialog box.

Hope you got an idea about overriding the Dialog Field methods in Dynamics AX... Enjoy in Dynamics AX World.

1 comment:

  1. Yes, I got it. Good explanation. Thanks Dayakar Reddy, Bangalore

    ReplyDelete