Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Unanswered

Query missing QueryBuildDataSource for FormDataSource SalesLineForeignTradeCategory.

Posted on by 434

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

  • Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    RE: Query missing QueryBuildDataSource for FormDataSource SalesLineForeignTradeCategory.

    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.
  • Ram Kumar Profile Picture
    Ram Kumar 434 on at
    RE: Query missing QueryBuildDataSource for FormDataSource SalesLineForeignTradeCategory.

    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
    Martin Dráb 230,188 Most Valuable Professional on at
    RE: Query missing QueryBuildDataSource for FormDataSource SalesLineForeignTradeCategory.

    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?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans