Contact Me

Total Pageviews

Thursday 7 August 2014

Filter Enum Values on Form Lookup Ax 2012 / Ax 2009

Often there are requirements/ design changes, where we need to filter and display on a few enum values in a Form lookup.

Often enough, we need to restrict the user selection from a particular ComboBox. Creating a new BaseEnum specifically for this purpose is a really cumbersome solution, which later might lead to problems of maintenance.

To use this class, you need to know only one static method:
public static SysFormEnumComboBox newParameters(
    FormRun _formRun,
    int     _comboBoxControlId,
    enumId  _enumId,
    Set     _allowedEnumValuesSet,
    Form    _form = null)

And here is an example of how you would use it:
sysFormEnumComboBox = SysFormEnumComboBox::newParameters(element, 
    control::ComboBoxOnForm, 
    enumnum(SalesType), 
    enumSet);

which means that the control ComboBoxOnForm will be bound to BaseEnum Sales Type, containing only values, found in the Set enumSet.

This code basically filters the enum based on the values from Set.


public class FormRun extends ObjectRun
{
    SysFormEnumComboBox         sysFormEnumComboBox;
    Set                         enumSet;// = new Set(Types::Enum);
}

In init method of form:

    enumSet= new Set(Types::Enum);
    enumSet.add(SalesType::Blanket);
    enumSet.add(SalesType::Journal);
    enumSet.add(Salestype::Sales);

    sysFormEnumComboBox  =      sysFormEnumComboBox::newParameters(element,control::ComboBoxOnForm,enumNum(SalesType),enumSet);

     super();

Happy Daxing! :)

1 comment:

  1. looks great. can it be made working on the dialog() as well?

    ReplyDelete