Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

cant able to clear the ranges for filter in display field

(0) ShareShare
ReportReport
Posted on by 454

Hi,

I have placed one display field in a form. I have override the context method to write code for filter. The filters works fine but when i tried clearing the ranges applied for the filter i am facing one error called " Query missing QueryBuildDataSource for FormDataSource SalesLine".     Help me on this.

 

public void context()
{
    int             selectedMenu;
    formrun         fr;
    Args            ag;
    Name            strtext;
    querybuilddataSource qb1;
    queryrun    qr;
    query       q;
    PopupMenu menu = new PopupMenu(element.hWnd());
    int a = menu.insertItem('Filter By Field');
    int b = menu.insertItem('Filter By Selection');
    int c = menu.insertItem('Remove Filter');
    ;
q   = Salestable_ds.query();
qb1 = q.dataSourceTable(tablenum(Salestable));
qb1 = qb1.addDataSource(TableNum(Salesline));
qb1.relations(true);
selectedMenu = menu.draw();

    switch (selectedMenu)
    {
    case -1: //Filter by field
            break;
    case a:
            ag = new args('SysformSearch');
            fr = new formrun(ag);
            fr.run();
            fr.wait();
//Reading User entered value for filter process
            strtext = fr.design().controlName('findedit').valueStr();
            if(strtext)
            {
//Creating a query for filter
                qb1.addRange(FieldNum(Salesline,CustAccount)).value(strtext);
                Salestable_ds.query(Q);
                Salestable_ds.executeQuery();
            }
            break;
    case b:                                      // Filter By Selection
            qb1.addRange(FieldNum(Salesline,CustAccount)).value(customeraccount.valueStr());
            //info(customeraccount.valueStr());
            Salestable_ds.query(Q);
            Salestable_ds.executeQuery();
            break;
    case c :                                      // Remove Filter
            q   = new Query();
            qb1 = q.addDataSource(tablenum(Salestable));
            qb1.clearLinks();
            qb1.clearRanges();
            Salestable_ds.query(Q);
            Salestable_ds.removeFilter();

            break;
    Default:
            break;
    }

}

Regards,

Ram

  • Suggested answer
    nmaenpaa Profile Picture
    101,156 Moderator on at
    RE: cant able to clear the ranges for filter in display field

    My advice is that if you want to be able to filter by some field, don't create it as a display field.

    Instead add new data sources on your form to bring the field to the form as a physical field.

    Display fields should be used only when filtering is not needed.

  • Ram Kumar Profile Picture
    454 on at
    RE: cant able to clear the ranges for filter in display field

    Hi Nikolaos,

    I am trying to filter on display field for my learning since im new to AX.

    Regards,

    Ram

  • nmaenpaa Profile Picture
    101,156 Moderator on at
    RE: cant able to clear the ranges for filter in display field

    By the way, as mentioned earlier (here community.dynamics.com/.../display-method-in-formdatasource ), I don't understand what requirement you are trying to solve with your code. Your form has data source SalesTable. And you want to display customer account and filter by it. There shouldn't be any need to add a display field to show it and all this code to filter by it.

    Could you let us know the business requirement that you are working with? Perhaps we can help you save some time and money.

  • Suggested answer
    nmaenpaa Profile Picture
    101,156 Moderator on at
    RE: cant able to clear the ranges for filter in display field

    I guess you should clear ranges from both data sources (SalesTable and SalesLine).

    In order to do that, I recommend to save them in two different variables (qb1 and qb2) so that you can clearRanges() for both later in the method.

  • Ram Kumar Profile Picture
    454 on at
    RE: cant able to clear the ranges for filter in display field

    Hi Nikolaos,

    I have deleted the lines you have told but it doesnt clear the filter. But the error is not popping now.

    Regards,

    Ram

  • Suggested answer
    nmaenpaa Profile Picture
    101,156 Moderator on at
    RE: cant able to clear the ranges for filter in display field

    In your case c (remove filter) you try to create a new query and a new data source, and then clear ranges of that new data source.

    I think you should instead clear range of the existing data source (which you have in variable qb1). Try to remove lines 47 and 48 of your code and it might work.

    For additional troubleshooting, please debug it and let us know what line is throwing the error.

  • Blue Wang Profile Picture
    on at
    RE: cant able to clear the ranges for filter in display field

    Hi Ram,

    Your needs are the same as this thread?

    community.dynamics.com/.../query-missing-querybuilddatasource-for-formdatasource-saleslineforeigntradecategory

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,207 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,923 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans