We all know there are various ways of doing this in AX 2009, but in AX 2012, We have a new class which will help to easily achieve this through DialogEnumComboBox class.
As you see below, the sales status drop down will only show the Canceled and Invoiced elements though the enum has more elements in it.
Now, lets see how to do this. Create class and methods as shown below.
public class TestDialogEnumComboBox extends RunBaseBatch
{
DialogEnumComboBox dialogEnumComboBox;
DialogField dialogType;
DialogRunBase dialog;
SalesStatus salesStatus;
#define.FieldNoTmp(600)
}
public Object dialog()
{
Set enumSet = new Set(Types::Enum);
dialog = super();
dialogType = new DialogField(dialog, enumStr(SalesStatus), #FieldNoTmp);
dialog.addCtrlDialogField(dialogType.name());
dialogType.init(dialog);
dialogType.label("Sales status");
dialogType.helpText("Select sales status.");
dialogType.value();
enumSet.add(SalesStatus::Canceled);
enumSet.add(SalesStatus::Invoiced);
dialogEnumComboBox = DialogEnumComboBox::newParameters(null, dialogType.control().id(), enumNum(SalesStatus), enumSet, dialog.form());
return dialog;
}
public void dialogPostRun(DialogRunbase _dialog)
{
super(_dialog);
_dialog.dialogForm().formRun().controlMethodOverload(true);
_dialog.dialogForm().formRun().controlMethodOverloadObject(this);
_dialog.formRun().controlMethodOverload(true);
_dialog.formRun().controlMethodOverloadObject(this);
if (dialogEnumComboBox)
{
// Specify the formRun (at this point the formRun is already available)
// This is needed to track selection in the comboBox
dialogEnumComboBox.parmFormRun(dialog.dialogForm().formRun());
// Select a specific entry in the comboBox, if needed
dialogEnumComboBox.select(SalesStatus::Invoiced);
}
}
public boolean getFromDialog()
{
boolean ret;
ret = super();
if (dialogEnumComboBox)
{
salesStatus = dialogEnumComboBox.selection();
}
return ret;
}
client server static ClassDescription description()
{
return "DialogEnumComboBox example";
}
public static void main(Args _args)
{
TestDialogEnumComboBox testDialogComboBox = new TestDialogEnumComboBox();
if (testDialogComboBox.prompt())
{
testDialogComboBox.run();
}
}
public void run()
{
info(enum2str(salesStatus));
}
No comments:
Post a Comment