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

Community site session details

Session Id :
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)

(0) ShareShare
ReportReport
Posted on by 353

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

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    236,958 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.

  • Muhammad_Ali Profile Picture
    353 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

  • Muhammad_Ali Profile Picture
    353 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

  • Verified answer
    Muhammad_Ali Profile Picture
    353 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();
    }

  • Verified answer
    Martin Dráb Profile Picture
    236,958 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());
        }
    }
  • Muhammad_Ali Profile Picture
    353 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

  • Muhammad_Ali Profile Picture
    353 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

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 3

#3
Community Member Profile Picture

Community Member 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans