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 :
Finance | Project Operations, Human Resources, ...
Unanswered

Query missing QueryBuildDataSource for FormDataSource SalesLineForeignTradeCategory.

(0) ShareShare
ReportReport
Posted on by 456

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;
    }

}

8228.Screenshot_5F00_1.png

4300.Screenshot_5F00_3.png

Regards,

Ram

I have the same question (0)
  • Martin Dráb Profile Picture
    238,778 Most Valuable Professional on at

    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?

  • Ram Kumar Profile Picture
    456 on at

    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

  • Martin Dráb Profile Picture
    238,778 Most Valuable Professional on at

    All right, here are a few things you can learn from it:

    • You can't filter by display methods. Therefore if you need filtering, using a display method isn't a wise design choice. Consider alternatives, such as joining a data source, creating a view with a computed column or using a temporary table.
    • You wouldn't be able to upgrade your code to the next version, therefore you should avoid it.
    • Completely replacing a form query, as you did for the third case, is usually a bad idea.
    • If you run cases 'a' and/or 'b' multliple times, you will be adding multiple ranges, becuase your logic lacks removing or reusing ranges added before.
    • Use intrinsic methods, such as formStr(), instead of hard-coding object names.
    • Use classfactory.formRunClass() to create FormRun instances.

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!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 514 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 390

#3
Adis Profile Picture

Adis 266 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans