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

Notifications

Announcements

No record found.

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)
  • udaY-ch Profile Picture
    5,133 on at
    Hi 
     
    You have extended the view and added the field and i assume you added the correct enum reference to the field.
     
    Thanks
    Uday
  • Waed Ayyad Profile Picture
    9,039 Super User 2025 Season 2 on at
    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

  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,431 Super User 2025 Season 2 on at
     
    Can you confirm that "Auto Declaration" property is "Yes"
     
    Otherwise can you please share with us more details ?
     
    Best regards,
    Mohamed Amine MAHMOUDI
  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at
    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.
  • Waed Ayyad Profile Picture
    9,039 Super User 2025 Season 2 on at

    Hi @SA-20091232-0

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

    Thanks,

    Waed Ayyad

  • Suggested answer
    Saalim Ansari Profile Picture
    666 on at

    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
  • SA-20091232-0 Profile Picture
    89 on at
     
    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.
     
     
     
     
  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at
    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
    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.
     
     
     
     

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans