Hi,
I am new to AX. I have used a display field and tried to fillter that field by using Filter by field, Filter by selection option. when i tried to clear the filter it clears all the data from the form. The form looks empty and an error is popping like shown in the screenshot. Here i have attached my code also. 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 = SalesLine_ds.query(); qb1 = q.dataSourceTable(tablenum(SalesLine)); //qb1 = qb1.addDataSource(TableNum(CustTable)); //qb1.addLink(FieldNum(SalesLine,CustAccount),FieldNum(CustTable,AccountNum)); //qb1 = qb1.addDataSource(TableNum(SalesLine)); 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); SalesLine_ds.query(Q); SalesLine_ds.executeQuery(); } break; case b: // Filter By Selection qb1.addRange(FieldNum(SalesLine,CustAccount)).value(customeraccount.valueStr()); SalesLine_ds.query(Q); SalesLine_ds.executeQuery(); break; case c : // Remove Filter q = new Query(); qb1 = q.addDataSource(tablenum(SalesLine)); qb1.clearLinks(); qb1.clearRanges(); SalesLine_ds.query(Q); SalesLine_ds.removeFilter(); break; Default: break; } }
.
Regards,
Ram
All right, here are a few things you can learn from it:
Hi Martin,
I have done this for my learning only. I placed a display field Customer account in the form. so we cant filter directly.
Regards,
Ram
I moved the thread from D365 Finance forum to Dynamics AX forum, because the screenshots clearly aren't from D365FO.
Let me also make your code slightly easier to read:
public void context() { int selectedMenu = menu.draw(); FormRun fr; Args ag; Name strText; Query q = salesLine_ds.query(); QueryBuildDataSource qb1 = q.dataSourceTable(tablenum(SalesLine)); 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'); switch (selectedMenu) { case -1: //Filter by field break; case a: ag = new Args(formStr(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); SalesLine_ds.query(Q); SalesLine_ds.executeQuery(); } break; case b: // Filter By Selection qb1.addRange(FieldNum(SalesLine,CustAccount)).value(customeraccount.valueStr()); SalesLine_ds.query(Q); SalesLine_ds.executeQuery(); break; case c : // Remove Filter q = new Query(); qb1 = q.addDataSource(tablenum(SalesLine)); qb1.clearLinks(); qb1.clearRanges(); SalesLine_ds.query(Q); SalesLine_ds.removeFilter(); break; } }
What's the point of your code? Why don't you filter SalesLine.CustAccount field directly?
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156