How to Enable/Disable fields in a dialog

20 Feb

You can enable events for your dialog objects by overriding the method dialogpostRun:

public void dialogPostRun(DialogRunbase _dialog)

// allow to call the event methods of this class (e.g. fld900_1_modified() method)

Then you can create event methods on your dialog fileds like fld900_1_modified() where you can address other components in the dialog, and modify their properties.

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 (). 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);


// verify that the field name generated by the system is correct
if( != #dlgFlgEmplIdFieldName)
throw error(strfmt(“@SYS79285”,, #dlgFlgEmplIdFieldName));

// Add a new field and let the Dialog framework to do all the work by assigning the field id and initializing the control since there are no event methods for that field.
dlgFldEmplName = dialog.addFieldValue(typeid(EmplName), emplName, “@SYS54564”, “@SYS54564”);

return dialog;

Then you can get the value of fields using this method :

public boolean getFromDialog()
boolean ret;

ret = super();

// get the values from the dialog in order to save them in SysLastValue (using pack() method)
emplId = dlgFldEmplId.value();
emplName = dlgFldEmplName.value();

return ret;
verify whether a correct employee id has been specified

public boolean fld900_1_validate()
FormStringControl control = dialog.formRun().controlCallingMethod();
// verify whether a correct employee id has been specified
return EmplTable::checkExist(control.text());

The pack and unpack methods are used as following:

public container pack()
// pack the employee id and employee name and save them in SysLastValue
return [#CurrentVersion, #CurrentList];

public boolean unpack(container packedClass)
boolean ret;
Integer version = conpeek(packedClass,1);

switch (version)
case #CurrentVersion:

// get the employee id and employee name values from the container that has been saved in the SysLastValue record
[version, #CurrentList] = packedClass;
ret = true;

ret = false;

return ret;

Finally, in the main method :

static void main(Args args)
SETutorialDialogControlEvent seTutorialDialogControlEvent = SETutorialDialogControlEvent::construct();
// show the dialog
if (seTutorialDialogControlEvent.prompt())
// if OK is pressed, run some code (in that case, run() method should be overriden in the current class);
Where SETutorialDialogControlEvent is defined as following:

public static SETutorialDialogControlEvent construct()
return new SETutorialDialogControlEvent();


As you can see the macro #dlgFlgEmplIdFieldNo is used to assign the ID to the dialog control.
Overriding the event methods (e.g. modify, validate, selectionChange) on dialog controls is not as straight forward as it is on form controls.

Leave a comment

Posted by on February 20, 2012 in X++



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

All About Dynamics 365

Dynamics 365, D365, Implementor

Syed Rafay Ali

This blog contains information about Functional techniques and guidelines in Microsoft Dynamics AX, including tips, tricks, tutorials, tools and upcoming news enhancement in Microsoft Dynamics Ax

Philippsen's Blog

Everyday findings in my world of .net and related stuff

Microsoft Dynamics AX

A great site


All things Blockchain, ERP and IoT

Dynamics Ax

Technical Knowledge


A blog about implementing Microsoft Dynamics AX and Dynamics 365 for Operations

Microsoft Dynamics 365 Blog

Strat your organization's digital translation with Dynamics 365, A Blog by Sandeep Chaudhury

DEVSerra - Dynamics AX development blog

Your official Microsoft Dynamics AX blog.


Discovering Dynamics


A blog by Hai Nguyen

Learn Dynamics Ax with Johnkrish

Live as if you were to die tomorrow. Learn as if you were to live forever - Mahatma Gandhi ****** The more I learn, the less I know - Albert Einstein

Twisted Untwirled

Just another site


Just another site

guyterry's Dynamics AX blog

Just another Dynamics AX blog

%d bloggers like this: