Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Populate Data on a form Grid only after using Advanced filter/sort. (Grid should display no Data prior to using Advanced filter/sort)

Posted on by 345

Hi -

   I have designed a custom form with Advanced filter/sort button (Label - Main Account Filter). Please take a look at the screen shot.

6116.Capture.JPG

The Advanced filter/sort functionality works just fine. The Problem I'm having is that when I run the form the data is first populated on the grid and only then I can use the Advanced filter/sort button to filter the data. My question is that is there any way I can use the Advanced filter/sort before the data is populated on the form.

For example - I want the form to run and show no data on the grid. Then I can go and use Advanced filter/sort to filter and refresh the form to display the filtered data.

The reason I want to Implement this  is because there will be a very large population of records that will be a part of this form.  For speed/performance purposes, it would be good to be able to filter the population down before the query runs – rather than generating the full population of results and then filtering.

Is there a way I can implement this ?

Thank You for you help

*This post is locked for comments

  • Muhammad_Ali Profile Picture
    Muhammad_Ali 345 on at
    RE: Populate Data on a form Grid only after using Advanced filter/sort. (Grid should display no Data prior to using Advanced filter/sort)

    Martin -

    My bad your idea and code for DS init() works great ! I forgot to change the AutoSearch Property back  to Yes for my DS. That's why the grid was always empty after selecting the criteria. It works fine now.

    Thanks

  • Muhammad_Ali Profile Picture
    Muhammad_Ali 345 on at
    RE: Populate Data on a form Grid only after using Advanced filter/sort. (Grid should display no Data prior to using Advanced filter/sort)

    Hello Martin -

    Agreed - This seems a much better Idea to display the criteria first and then execute the form with data. I have added your piece of code in my init() of DS but I'm facing a minor problem which is that now the form opens up with no data but If only If I refresh the form (F5) it displays the data according to my Query Criteria. Is there a way I can add a code which will refresh my form automatically instead of the user manually refreshing the form ? I think it is Important to display the records on the form as soon as the criteria is selected instead of refreshing the form manually every time you open the form for the first time. what do you think ?

    Thanks

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,149 Most Valuable Professional on at
    RE: Populate Data on a form Grid only after using Advanced filter/sort. (Grid should display no Data prior to using Advanced filter/sort)

    I thought I would open the dialog from code, rather than letting users to click the button, because they can't use the form until they choose the criteria.

    When I was preparing a sample code for you, I realized that it's not needed to disable AutoSearch and executing the query from code; we can simply show the dialog when initializing the form.

    You could put the following code to init() method of your datasource.

    public void init()
    {
        QueryRun qr;
    
        super();
    
        qr = new QueryRun(this.query());
        if (qr.prompt())
        {
            this.query(qr.query());
        }
    }
  • Verified answer
    Muhammad_Ali Profile Picture
    Muhammad_Ali 345 on at
    RE: Populate Data on a form Grid only after using Advanced filter/sort. (Grid should display no Data prior to using Advanced filter/sort)

    I found the solution on this issue. It was a reply from Martin on the other forum. here is the link to it.

    dynamicsuser.net/.../populate-data-on-grid-launch

    I added some code in forms init(), Run() and datasource executequery() method. The idea was to populate the grid with a record displaying values with 0. This way the Advance Filter/ Sort functionality will be visible on the form and ready to use. The user can then filter the records which will be displayed on the Grid.

     public class FormRun extends ObjectRun
    {
        boolean started;
    }

    public void run()
    {
        super();
        started = true;
    }

    public void executeQuery()
    {
        if (started)
        {
            table1_ds.queryBuildDataSource().clearRange(fieldNum(Table1, RecId));
            table1_ds.queryRunQueryBuildDataSource().clearRange(fieldNum(Table1, RecId));
        }
        else
        {
             table1_ds.queryBuildDataSource().addRange(fieldNum(Table1, RecId)).value(queryValue(0));
        }
        super();
    }

  • Muhammad_Ali Profile Picture
    Muhammad_Ali 345 on at
    RE: Populate Data on a form Grid only after using Advanced filter/sort. (Grid should display no Data prior to using Advanced filter/sort)

    Martin Can you please give me some more details on this ? Thanks

  • Muhammad_Ali Profile Picture
    Muhammad_Ali 345 on at
    RE: Populate Data on a form Grid only after using Advanced filter/sort. (Grid should display no Data prior to using Advanced filter/sort)

    Hi Martin -

      OK now The first half of my problem is solved. Now the form opens up without any data after changing the Auto Search to No on a Datasource as you said.

    But now my Advance Filter/Sort button is not working. (When I click on it no query window opens) I know you mentioned something about Executing the query from code. Can you please suggest a thread if there is any which will help me learn about "execute a query with code" ?

    Thanks Again

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,149 Most Valuable Professional on at
    RE: Populate Data on a form Grid only after using Advanced filter/sort. (Grid should display no Data prior to using Advanced filter/sort)

    You can set the data source with AutoSearch=No and execute the query from code when you're ready.

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans