DialogEnumComboBox class in AX 2012 [X++, Restrict Enum elements in the dialog fields]

Friends,

It has been long time since I have posted. Clients always keeps us busy :)

Today’s post is very simple and quick way of restricting the Enum elements in the dialog fields in the dialogs.

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.

image

Now, lets see how to do this. Create class and methods as shown below.

public class SR_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)

{

    SR_TestDialogEnumComboBox testDialogComboBox = new SR_TestDialogEnumComboBox();

 

    if (testDialogComboBox.prompt())

    {

        testDialogComboBox.run();

    }

}

public void run()

{

    info(enum2str(salesStatus));

}

Happy Dax6ng,

Sreenath Reddy

image

About these ads

One Response to “DialogEnumComboBox class in AX 2012 [X++, Restrict Enum elements in the dialog fields]”

  1. Joris dG Says:

    Nice. Considering RunBase is no longer “the” way to go, but sysOperation is, any word on a similar feature for data contract dialogs?


Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 159 other followers

%d bloggers like this: