Adding Enum Filter with "All Values" Option in Dynamics 365 Finance and Operations - Microsoft Dynamics 365 Vietnam

Microsoft Dynamics 365 Vietnam

Song Nghia - Microsoft Dynamics 365 Vietnam

Breaking

Wednesday, June 26, 2024

Adding Enum Filter with "All Values" Option in Dynamics 365 Finance and Operations

 Adding Enum Filter with "All Values" Option in Dynamics 365 Finance and Operations

Customers often request specific filters in forms based on enums, including an option to display all records regardless of field value. This guide illustrates how to add a ComboBox control to achieve this functionality.

Algorithm Overview

  1. Add an unbounded ComboBox control to the form.
  2. Add "All" element and required base enum elements to the control during form initialization.

Code Implementation

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 ComboBox the same label as 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();
}

Result



The ComboBox control will now include the "All values" option along with the base enum elements, allowing users to filter records based on specific enum values or select "All values" to display all records.

By implementing this approach, you provide users with a flexible filtering option that enhances usability and meets customer requirements effectively.

No comments:

Post a Comment