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 :
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

I have the same question (0)
  • Blue Wang Profile Picture
    on at

    Hi Ram,

    Your needs are the same as this thread?

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

  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    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.

  • Ram Kumar Profile Picture
    454 on at

    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,162 Moderator on at

    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.

  • nmaenpaa Profile Picture
    101,162 Moderator on at

    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.

  • Ram Kumar Profile Picture
    454 on at

    Hi Nikolaos,

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

    Regards,

    Ram

  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    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.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 456 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans