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
        formComboBoxControl.enumType(0);
        
        //Give the Combo box the same label of ABC enum
        formComboBoxControl.label(dictEnum.label());

        //Set the number of elements of the comboBOX (the elements of ABC plus one)
        formComboBoxControl.items(numOfValues);

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

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

        dialog.run();

   }

The result will be this one

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