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)

Programatically accessing current list page query state

(0) ShareShare
ReportReport
Posted on by

I have a list page (based on the ProjProjectsListPage) with several ways for the user to filter the records, and it seems that some of them aren't aware of any changes the others may have made.  Can anyone please explain what I'm missing?

Filter methods:

  1. Standard Advanced Filter/Sort button behind CTRL+F3 shortcut
  2. Custom controls for FD filtering, above the grid & next to the standard Show projects and Show levels dropdowns.  Said controls have modified methods - i.e. within the Form - that call a custom method on the ProjProjectListPageInteraction class
  3. Custom buttons on the Action Pane that call a custom class that then makes a call to the same custom method on the ProjProjectsListPageInteraction class

The list page uses a custom query as its data source, to which a range for the current user is added programatically in ProjProjectsListPageInteraction::initializeQuery.  If the user first removes this range using the Advanced Filter/Sortbutton and then uses either (2) or (3), the methods in the ProjProjectsListPageInteraction class are using the code below in an attempt to retrieve the current state of the query/filtering.

FormDataSource fds;
Query query;

fds = this.listPage().activeRecord('ProjTable').datasource();
if(fds}
{
    query = fds.query();
}

However, if i put a breakpoint after the brace, the query variable still shows the the range in place.  Is there any way to get the current state of the query in the list page interaction class?

*This post is locked for comments

I have the same question (0)
  • Otavio Anaga Profile Picture
    216 on at

    you need to use something like this:

    YourDataSource_Ds.queryRun().query();

    If it helped you, please mark as an answer!

  • Stijn Mattens Profile Picture
    10 on at

    Hellow Rich,

    What you can do in this case is getting the correct FormDataSource form you ListPage object.

    Example for CustTableListPage:

    FormDataSource fds;
    Form form = new Form(FormStr(CustTableListPage));
    ;

    fds = this.listPage().activeRecord(form.datasource(1).name()).dataSource();

    fds.query();

    If you want to find a range/filter for a corresponding fieldvalue, you can use 'findRange'

    Syntax: QueryBuildDataSource.findRange(fieldNum(tableName, fieldName)).value();

    If this answer is usefull to you, please mark it as an answer

  • Community Member Profile Picture
    on at

    Thanks Otavio: I can see in debugging & in UI execution that has the desired effect of allowing the custom code - (2) and (3) in my initial explanation - to retrieve the current state.  Now I need to work out how I can apply ranges to the query object thus retrieved.  The code I've inherited would add new ranges as below - whilst resetting any changes applied by (1) - but I can't get a QueryBuildDataSource object from the Query object, can I?

    Previous code that added a range:

    QueryBuildDataSource  qbdsParent, qdbsLinkTable;
    
    FormDataSource        fds;
    
    fds = this.listPage().activeRecord('ProjTable').dataSource();
    if(fds)
    {
        qbdsParent = fds.queryBuildDataSource();
    }
    
    qdbsLinkTable = qbdsParent.addDataSource(tableNum(ProjTableLinkedCustomTable));
    qdbsLinkTable.addLink(fieldNum(ProjTable,ProjId), fieldNum(ProjTableLinkedCustomTable, ProjId));
    qdbsLinkTable.addRange(fieldNum(ProjTableLinkedCustomTable, FilterColumn)).value(SysQuery::value(parameter));


    I've tried the following two approaches:

    /* Shows the query variable changed whilst debugging, doesn't affect UI filtering */
    Query query, qryCheckBack;
    QueryBuildDataSource qbdsParent, qdbsLinkTable;
    FormDataSource fds;
    
    fds = this.listPage().activeRecord('ProjTable').dataSource();
    if(fds)
    {
        query = fds.queryRun().query();
    }
    
    qdbsLinkTable = query.dataSourceTable(tableName2id('ProjTableLinkedCustomTable'));
    qdbsLinkTable.addRange(fieldNum(ProjTableLinkedCustomTable, FilterColumn)).value(SysQuery::value(parameter));
    
    fds.query(query);
    fds.queryRun().query(query);
    
    qryCheckBack = fds.queryRun().query(); //Debugging seems to confirm that the updated query should now be in place
    qryCheckBack = fds.query(); //Debugging seems to confirm that the updated query should now be in place

    And as an alternative:

    /* Shows the query variable changed whilst debugging, doesn't affect UI filtering */
    Query query, qryCheckBack;
    QueryBuildDataSource qbdsParent, qdbsLinkTable;
    FormDataSource fds;
    
    fds = this.listPage().activeRecord('ProjTable').dataSource();
    if(fds)
    {
        query = fds.queryRun().query();
    }
    
    query.dataSourceTable(tableName2id('ProjTableLinkedCustomTable')).addRange(fieldNum(ProjTableLinkedCustomTable, FilterColumn)).value(SysQuery::value(parameter));
    
    fds.query(query);
    fds.queryRun().query(query);
    
    qryCheckBack = fds.queryRun().query(); //Debugging seems to confirm that the updated query should now be in place
    qryCheckBack = fds.query(); //Debugging seems to confirm that the updated query should now be in place

    I thought switching from executeQuery() to research() might do the job, but sadly that has no apparent impact. Looks like I might be half way to the solution now: (2) and (3) can access the changes from (1), but I can no longer make changes that are then applied.

  • Community Member Profile Picture
    on at

    Stijn,

    Thanks for the suggestion, but using Form.datasource(1).name() approach as the input to this.listPage().activeRecord() didn't appear to be any different to using the first table name.  I didn't see your suggestion before posting the update of 12 Jun 2017 12:48 PM, but Octavio's suggestion to use queryRun() appears to be at least half the answer.  That allows the current state of the query to be accessed: now I need to work out how to set it back for the next update/refresh of the list page contents.

  • Otavio Anaga Profile Picture
    216 on at

    Hi Rich, use the below job to see that when you put available values to the customer accountNum, when you call queryRun.reset() everything works fine after the query has been modified:

    static void querieTest(Args _args)
    {
        Query query = new query();
        QueryRun queryRun;
        CustTable custtable;
        
        query.addDataSource(tableNum(CustTable));
        
        QueryRun = new QueryRun(query);
        
        queryRun.query().dataSourceTable(tableNum(CustTable)).addRange(fieldNum(CustTable,AccountNum)).value('CUSTOMER_1');
        
        info(queryRun.toString());
        
        while (queryRun.next())
        {
            custtable = queryRun.get(tableNum(CustTable));
            info(custtable.AccountNum);
        }    
        
        info(queryRun.toString());
        
        queryRun.query().dataSourceTable(tableNum(CustTable)).addRange(fieldNum(CustTable,AccountNum)).value('CUSTOMER_2');
        
        info(queryRun.toString());
        
        queryRun.reset();
        
        while (queryRun.next())
        {
            custtable = queryRun.get(tableNum(CustTable));
            info(custtable.AccountNum);
        }
    }


    Please, mark as an answer if it helped you!


  • Community Member Profile Picture
    on at

    Otavio,

    Thanks for that: perhaps I should have realised after your initial post that I should have been primarily working with the queryRun() object. Resetting it didn't seem to do anything, but behind the list page, the code below appears to write the range back to the datasource:

    Query query, qryCheckBack;
    QueryBuildDataSource qbdsParent, qdbsLinkTable;
    FormDataSource fds;
    
    fds = this.listPage().activeRecord('ProjTable').dataSource();
    if(fds)
    {
        query = fds.queryRun().query();
    }
    
    query.dataSourceTable(tableName2id('ProjTableLinkedCustomTable')).addRange(fieldNum(ProjTableLinkedCustomTable, FilterColumn)).value(SysQuery::value(parameter));
    
    fds.queryRun(new QueryRun(query));

    I'm still not sure why the queryRun().query(parameter); call doesn't write the parameter to the datasource in the same way the above code does, but at least I now know how to access current state & write it back (perhaps I should have been more specific in my initial thread title).

    That said, I've stumbled across the Filter Pane control options and, with the fields in question being part of the query behind the list page, I'm wondering why the original developer was ever attempting to use X++ rather than AOT properties... Perhaps a salutory lesson to look more closely at the DOM before cutting code.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Basit Profile Picture

Basit 1

#1
GL-01081504-0 Profile Picture

GL-01081504-0 1

#1
Roya Profile Picture

Roya 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans