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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

clearRanges before filter by field

(0) ShareShare
ReportReport
Posted on by 927

I have a form with 1 queryBuildRange on it and executes the range in the ExecuteQuery() method on the datasource. How can I clearranges before filtering for specific value (when doing right-click mouse on formgrid and filterByField)?

 

*This post is locked for comments

  • Jo Neetesonne Profile Picture
    175 on at

    Not sure what you want to achieve, but clearing a specific range can be done like this:

    queryBuildDataSource.clearRange(fieldNum('Table name','Field name'));

  • Glenn Lissone Profile Picture
    927 on at

    which statement do I need as if and else criteria? So when the forms open .addrange and when user do right-click mouse remove alle ranges and filter by field?

    public void executeQuery()

    {

       ;

       //what is the criteria needed in the if/else statement?

       //if filter not used and form is default opened

           this.query().dataSourceNo(1).addRange(fieldNum(projTable, responsible)).value('userA');

           this.query().dataSourceNo(1).addRange(fieldNum(projTable, status)).value(enum2str(projStatus::finished));

       //else when filter is set via "right-mouse click-filter by field"

           //1. first remove all ranges  

           this.query().dataSourceNo(1).clearRanges();

           //2. apply new filters by field

       super();

    }

  • Suggested answer
    DG Profile Picture
    1,226 on at

    Hi Glenn,

    The 'filter by field' feature is designed to put a filter on the existing query. What you are trying to do is reset the existing query and then apply filter. So, in my opinion, this is not a good design. If I were you, I would have put extra drop down filter(s) on the top of form and populate them with relevant values; for example 'user A' and project status 'finished'. And apply filter in selection changed methods of these drop-down boxes. So user would have visibility and flexibility to set filters and view relevant data.

    Now that being said, If you still want to go ahead with your idea

    1. Move the code of initializing the filter ranges to the 'init' method of the datasource.

    2. Override the 'context' method of the field in question. You need to write your own 'Filter by field' code here. You have the option to completely surpress the standard context menu and just have your menu options. Alternatively you can append your option at the end of standard menu list. For more how to do that see this blog learnax.blogspot.co.uk/.../build-your-own-context-menu-on-form.html

    3. Please ensure that you also put code for removing the filter. That will be for setting initial ranges back.

    Hope this helps.

    Regards,

    Deepak

  • Suggested answer
    Amir Nazim Profile Picture
    5,994 on at

    executeQuery method is not the right place to code for this scenario? as it always executes.

    instead  try moving your code in Init method of datasource.

  • Glenn Lissone Profile Picture
    927 on at

    If I follow your first method is it then also possible to set the value, when user filter with right-click mouse "filterbyfield" back to the combobox? If not is it then possible to disable right-mouse click filterbyfield?

  • Suggested answer
    Community Member Profile Picture
    on at

    You can use the method SysQuery::findOrCreateRange(...). It will check if the range already exists and reuse it, otherwise it creates it.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans