web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Custom filter is not working on form

(2) ShareShare
ReportReport
Posted on by 89
I have a custom form and I want to add a custom filter on that form. I have created an enum with 2 values: ALL and SUMMARY. I followed a tutorial https://dynamics365musings.com/executequery-method-in-d3656-forms/ for that purpose. 
I followed the following steps,
I created a combobox and added my created enum to its properties.
Override the selectionChange method for this combobox and call the executeQuery method of form datasource on which I want to apply filter.
On the executeQuery method of the datasource, I have written the following code:
 
Following is the control for a custom filter
 
 
The filter does not work. What should be done, any suggestions?
I have the same question (0)
  • SA-20091232-0 Profile Picture
    89 on at
    Custom filter is not working on form
    I'm using the same enum for both, the filter combobox and the field of the table, both have the same enum, it returns 0 and 2 instead of 0,1.
    Following is the screenshot of the enum.
     
     
     
     
  • Martin Dráb Profile Picture
    236,275 Most Valuable Professional on at
    Custom filter is not working on form
    Please answer whether the field uses the same enum as your filter control. You showed that the control uses *SummaryFilterEnum, but you didn't tell us anything about the data type of your *IsSummary field.
     
    By the way, it's a bit surprising that the value of your range is 2. You said you created an enum with two values, therefore I would expect values 0 and 1. Other numbers can be used, of course, but it may be worth checking that everything is correct there.
  • SA-20091232-0 Profile Picture
    89 on at
    Custom filter is not working on form
     
    Following is what my method returns: it returns me the query that I want . If I use the init method and put my range there and try to use the update the range on modified method of filter it still does not work (for modified event).
     
    Auto declation is also yes.
     
     
     
     
  • Suggested answer
    Saalim Ansari Profile Picture
    648 on at
    Custom filter is not working on form

    Hi @SA-20091232-0,

     

    Just to add to what others have already mentioned:

    Here's a cleaner and safer version of your executeQuery():

    public void executeQuery()
    {
        QueryBuildDataSource qbds = this.query().dataSourceTable(tablenum(ProjPostTransView));
        int selectedValue = SummaryFilter.selection();
    
        if (selectedValue != -1) // -1 can be used for 'ALL'
        {
            qbds.findOrCreateRange(fieldnum(ProjPostTransView, Summary))
                .value(queryValue(selectedValue));
        }
        else
        {
            // Optional: remove range if needed
            qbds.clearRange(fieldnum(ProjPostTransView, Summary));
        }
    
        super();
    }
    
    
    Also, make sure your combo box’s selectionChanged() method calls ProjPostTransView_ds.executeQuery(); so the filter is applied immediately on selection.
     
    Hope it helps ;) and let me know if you need more help!
    Saalim
  • Waed Ayyad Profile Picture
    8,952 Super User 2025 Season 2 on at
    Custom filter is not working on form

    Hi @SA-20091232-0

    Is your issue resolved? If yes, mark the answers that helped you as verified. 

    Thanks,

    Waed Ayyad

  • Martin Dráb Profile Picture
    236,275 Most Valuable Professional on at
    Custom filter is not working on form
    Don't look just at what the query returns - look at the query itself to see whether your code created what you intended.
     
    Does the field uses the same data type?
     
    By the way, removing all ranges doesn't sound like a good idea to me. A possible approach is adding a range in init() and just changing its value, or using findOrCreateRange(). An even more robust approach is removing other ranges for the given field.
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,316 Super User 2025 Season 2 on at
    Custom filter is not working on form
     
    Can you confirm that "Auto Declaration" property is "Yes"
     
    Otherwise can you please share with us more details ?
     
    Best regards,
    Mohamed Amine MAHMOUDI
  • Waed Ayyad Profile Picture
    8,952 Super User 2025 Season 2 on at
    Custom filter is not working on form
    Hi,
     
    Did you try to trace the code? Try to add break point on selection Change method, change the Enum value and start debugging, then tell us what the result is.

     

    Thanks,

    Waed Ayyad

    If this helped, please mark it as "Verified" for others facing the same issue

  • udaY-ch Profile Picture
    5,106 on at
    Custom filter is not working on form
    Hi 
     
    You have extended the view and added the field and i assume you added the correct enum reference to the field.
     
    Thanks
    Uday

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,239

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 903 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 604 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans