Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Filtering child grid from parent grid - User filter issues on child grid

Posted on by 50

Ahoy hoy,

I've inherited a form that has two grids on it.  The top grid are the headers to custom AP headers.  When a header is added/selected, the second grid then uses ranges to filter down the charges (MarkupTrans) that match to the header.  All of this works great.

But, I've received a request to add the ability to update a field on all of the filtered charge records.  Basically a mark all feature instead of clicking on each charge. This is where things go off the rails and I don't know why.

My repro steps are to create a new header.  I then head to the charges grid and filter them based on a field in the grid.  So, at this point, I have ranges filtering the grid that are driven by the selection in the parent and a user filter.  The displayed results in the grid looks perfect.  But, when I iterate in x++ through the data source backing the grid, it does not respect the user filter.  It only respects what was set on the range.  It's like the user filter is only affecting the display and that's it.

If I create a new header, select a different header, then select the header I created again, add the user filter to the charges, and iterate again, I get the expected results.  It's like this is only happening on a new AP header and not on existing ones.

This is almost like there's something not saving or refreshing along the way and I'm soooooo confused.  I've tried to force data source writes, using the standard select all lines with selection helper, and using the data source's queryrun.query all with the same results.  It will always respect the range, but never any user filters on the grid.  The executeQuery on the MarkupTrans_DS looks like it's just setting the range values so I don't know if there's something funky going on there.

Has anyone seen this before?  Is there anything else I should be searching for to help me figure out this issue?  Any ideas?

*This post is locked for comments

  • Verified answer
    Richard K Profile Picture
    Richard K 50 on at
    RE: Filtering child grid from parent grid - User filter issues on child grid

    Alright, so I found something that actually worked for me with this.  It's ugly, I hated it, but it solved the business need.  Don't judge me for this.  I SAID DON'T JUDGE ME!

    On the bottom grid, I overrode the enter event and added the following.

    public void enter()
    {
    
        //if the top grid record hasn't been saved, make sure it is before we do anything on the bottom grid
        if(!TLMFreightInvoiceHeader.RecId)
        {
            TLMFreightInvoiceHeader.insert();
        }
    
        super();
    }


    That's what actually worked for me.  By forcing the top grid to actually save it's new record, I was able to filter the bottom grid properly.

  • Richard K Profile Picture
    Richard K 50 on at
    RE: Filtering child grid from parent grid - User filter issues on child grid

    So, based on my description of the problem above, I found this chunk of code which displays any user filters (non-range filters).

    //show all user defined filters
    Query q = MarkupTrans_DS.queryRun().query();
    QueryFilter qf;
    int i;
    
    for (i = 1; i <= q.queryFilterCount(); i++)
    {
        qf = q.queryFilter(i);
        info(strFmt("%1: %2", qf.field(), qf.value()));
    }
        
    info('done');


    If I follow my steps above, it will not show any user filters.  But, as soon as I swap to another record and back in the parent grid, this works just fine and will show my user filters.

    I think my issue is that the parent data source isn't actually doing it's insert when I move to the child grid to enter the user filter.  For some reason, when it's not saved, the child grid will not retain it's user filter.   If I do a MarkupTrans_DS.research on the child grid, it will drop any user filter I've put in ( clears it out ).  

    PS: Thanks for that link. I remember reading through that a while ago, but it's always a good refresher.

  • Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: Filtering child grid from parent grid - User filter issues on child grid

    Hi Richard K,
    You have not shared any code, so it's just a wild guess, but often people do not know the difference between  formDataSource.query() and formDataSource.queryRun().query() and use them incorrectly, so I will just paste a quote  from http://kashperuk.blogspot.com/2010/03/tutorial-reread-refresh-research.html here

    formDataSource.queryRun().query() vs formDataSource.query()
    An important thing to mention here is that the form has 2 instances of the query object - one is the original datasource query (stored in formDataSource.query()), and the other is the currently used query with any user filters applied (stored in formDataSource.queryRun().query()).
    When the research method is called, a new instance of the queryRun is created, using the formDataSource.queryRun().query() as the basis. Therefore, if the user has set up some filters on the displayed data, those will be preserved.
    This is useful, for example, when multiple users work with a certain form, each user has his own filters set up for displaying only relevant data, and rows get inserted into the underlying table externally (for example, through AIF).
    Calling executeQuery, on the other hand, will use the original query as the basis, therefore removing any user filters.
    This is a distinction that everyone should understand when using research/executeQuery methods in order to prevent possible collisions with the user filters when updating the query.

    Read it and check if it is not causing your issue

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans