AX / D365FO – How to add enum filter with “All values”

Sometimes customers request a specific filter in a form. The filter is based on an enum and must have All element to display all records regardless of field value.

For example, a filter has 3 elements: AllQuotationOrder; although enum has only 2 elements: QuotationOrder.

To achieve the result you need to add a ComboBox control in code
The algorithm is the following:
– an unbounded combobox control is added to a form
– All element and required base enum elements are added to the control during form initialisation

Code below shows how to do

   public static void main(Args _args)
        Dialog dialog = new Dialog();
        DialogField dialogField;
        FormBuildComboBoxControl formComboBoxControl;

        EnumId   enumId   = enumNum(ABC);
        DictEnum dictEnum = new DictEnum(enumId);
        int      numOfValues  = dictEnum.values() + 1; 
        int      counter;

        //Add dialog field of type ABC
        dialogField = dialog.addField(enumStr(ABC));

        formComboBoxControl = dialogField.control();
        //Don't assign any enum type to Combobox
        //Give the Combo box the same label of ABC enum

        //Set the number of elements of the comboBOX (the elements of ABC plus one)

        //Insert ABC elements inside the combobox
        for(counter = 0; counter < numOfValues; counter ++)
            formComboBoxControl.item(counter + 1);

        //Add the "All values" element
        formComboBoxControl.text('All values');;


The result will be this one

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 )

Facebook photo

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

Connecting to %s