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 :
Microsoft Dynamics AX (Archived)

Edit a query and prompt for filters in a ListPage template form

(0) ShareShare
ReportReport
Posted on by 689

Hi, 

I need to add a few criteria to a query. Normally I would use addRange and then use QueryRun.prompt to get the users' filters, but I'm in a list page, and can't reassign the query with filters to the dataSource. I already tried overriding some of the initialization methods in the Interaction class, but there is no run or execute query method to override. We have performance issues due to an increasing number of records in a primary form so we want to query to avoid loading the entire table first. Is there any way in a ListPage form template to edit the query and prompt before that query is executed that does not revolve around creating duplicate objects?

Thanks

 

*This post is locked for comments

I have the same question (0)
  • Liviu Stoica Profile Picture
    160 on at

    Hello,

    Check if your listpage has a value for query properties in datasources, for example CustOpenInvoicesListPage.

    You can overwrite Run method from list page:

    public void run()
    {
        SysQueryRun queryRunCriteria;
    super(); queryRunCriteria = new SysQueryRun(CustTransOpen_ds.query()); // use first datasource from form query queryRunCriteria.promptAllowAddDataSource(false); if (queryRunCriteria.prompt()) { CustTransOpen_ds.query(queryRunCriteria.query()); } CustTransOpen_ds.executeQuery(); }

    Best regards,

    Liviu

  • Community Member Profile Picture
    on at

    Hi Guillaume,

    The initializeQuery() method on the ListPageInteraction class needs to be overridden to achieve this. This is where you can add ranges to your query. Take a look at the EcoResProductListPage.

    There is code to add filters based on where the listpage is called from.

  • Guillaume Cantin Profile Picture
    689 on at

    Hi Liviu,

    I am working with a template and interaction class, which in this case does not allow me to override the run method. In the initialize methods that give me access to the query, I am not able to get access to the static dataSource objects. I'm working with the ProjProjectsListPage form and ProjProjectsListPageInteraction class

  • Guillaume Cantin Profile Picture
    689 on at

    Hi Zubair,

    My ranges are added properly, but I need to prompt the user for criteria and then send that input to the datasource before executing my query. This is where I'm having an issue, as I cannot override a run or execute query method, the editor won't propose those methods in the list of methods that can be overriden. Does that mean I have to go deeper and override something in a base class?

    If not, is there a different way to push the results of a prompt to a query? I tried reassigning the results to the query object before the call to super() in initializeQuery() but to no avail.

  • Verified answer
    Guillaume Cantin Profile Picture
    689 on at

    I found the answer to my issue.

    Zubair, you were partly right in the sense that I had to use the initializeQuery method. The only part missing was query reassignment. I had to go and get the result of the activeRecord method in order to retrieve the FormDataSource reference I needed to update with the filtered query.

    The final code looks like this

    // Prior Declarations
    ProjTable           projTable;
    FormDataSource      formDataSource;
    
    /*
    (add ranges before this)
    */
    
    queryRun = new QueryRun(_query); // Where _query is a parameter from the initializeQuery method
    if (queryRun.prompt())
    {
        _query = queryRun.query();
        projTable = this.listPage().activeRecord(tableStr(ProjTable));
        formDataSource = projTable.dataSource();
        formDataSource.query(_query);
    }
    
        super(_query); // This is already there, and it's the reason I reassign the prompt result to the _query parameter
    
    ...

    The fact that activeRecord returns an empty record rather than a null reference is what allows us to go through with this approach. Also, there is no need to call executeQuery in this method for the FormDataSource as it is executed later.

    Thanks to everyone who pitched in on this

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans