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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Reg context of the display field.

(0) ShareShare
ReportReport
Posted on by 475

Hi guys,

I have created a display method to get displayproductnumber from ecoresproduct  to been shown in ecoresproductpercompanylistpage.

I have completed that,But what i want is to filter the display method fields,

I have done filter by selection and filter by field. Both are working but the remove filter is not working.

It is throwing some error whenever I run the form and click on the remove filter.

The required QueryBuildDataSource was not found in the Query associated with the FormDataSource '%1'. The QueryBuildDataSource should have the same name and table ID as the FormDataSource.

public void context()
{
int selectedMenu;
formrun fr;
Args ag;
Name strtext;
// SalesId sli;
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');
;

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
q =InventTable_ds.query();
qb1 = q.dataSourceTable(tablenum(InventTable));
qb1 = qb1.addDataSource(TableNum(EcoresProduct));
qb1.addLink(FieldNum(InventTable,Product),FieldNum(EcoresProduct,RecId));

qb1.addRange(FieldNum(EcoresProduct,DisplayProductNumber)).value(strtext);
InventTable_ds.query(Q);
InventTable_ds.executeQuery();
}
break;

case b: // Filter By Selection
q = InventTable_ds.query();
qb1 = q.dataSourceTable(tablenum(InventTable));
qb1 = qb1.addDataSource(TableNum(EcoresProduct));
qb1.addLink(FieldNum(InventTable,Product),FieldNum(EcoresProduct,RecId));
qb1.addRange(FieldNum(EcoresProduct,DisplayProductNumber)).value(StringEditEcoResProduct_DisplayProductNumber.valuestr());
InventTable_ds.query(Q);
InventTable_ds.executeQuery();

break;
case c : // Remove Filter

Default:


q = new Query();

qb1 = q.addDataSource(tablenum(InventTable));
qb1.clearLinks();
qb1.clearRanges();
InventTable_ds.query(Q);
InventTable_ds.removeFilter();
info("remove filter workigm");
break;


}

}

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    239,381 Most Valuable Professional on at

    The problem is that you're trying to create a completely new query (instead of modifying the one used by the form). The form likely has some joined data sources that you don't have in your query.

    Use 'InventTable_ds.query()' instead of 'new Query' and remove the existing range.

    By the way, wouldn't using a join be much easier than using a display method and adding all this logic?

    And are you aware of the existence of task()?

  • bharathkarunakaran Profile Picture
    475 on at

    Thank you martin,

    I have tried what you have said. But it doesn't work.

    I am getting the following error message,

    "Queries with multiple top level data sources cannot be applied to Forms."

  • Martin Dráb Profile Picture
    239,381 Most Valuable Professional on at

    You did something else. Stop trying to push a query to the data source, merely modify the query which is already there (if you really insist of doing all these things in code instead of simply adding a joined data source).

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 39

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans