Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

GroupBy on Lookup problem

(0) ShareShare
ReportReport
Posted on by

Hello,

I have problem with GroupBy query on Lookup. I have table TabA with price lists:

PriceListVersion | PriceSignCode | PriceSignDesc.

In table tabB I have column PriceListVersion, where a want check version of price list from popup. Each version should appear only once in the list.

I have code:

public void lookup(FormControl _formControl, str _filterStr)

{

    Query                   query = new Query();

    QueryBuildDataSource    queryBuildDataSource;

    SysTableLookup          sysTableLookup;

    ;

    sysTableLookup = SysTableLookup::newParameters(tableNum(TabA), _formControl);

    sysTableLookup.addLookupfield(fieldnum(TabA,PriceListVersion), true);

    queryBuildDataSource = query.addDataSource(tablenum(TabA));



    queryBuildDataSource.orderMode(orderMode::GroupBy);

    queryBuildDataSource.addGroupByField(fieldnum(TabA,PriceListVersion));



    sysTableLookup.parmQuery(query);

    sysTableLookup.performFormLookup();

}

I check Query in Debbuger, in queryBuildDataSource we have:

 SELECT FIRSTFAST * FROM PriceSignListTable GROUP BY PriceSignListTable.PriceListVersion

But still there is no grouping on the form:

  4667.popup.PNG

What's the most interesting, sometimes it works properly, although I don’t change anything on popup or datasource.

*This post is locked for comments

  • Tony Mok Profile Picture
    577 on at
    RE: GroupBy on Lookup problem

    Hi xelifchemnitz,

    It works for me. Thank you so much.

  • Suggested answer
    Hossein.K Profile Picture
    6,646 on at
    RE: GroupBy on Lookup problem

    Hi,

    Change your code like this:

    void orderNoLookup(FormControl _control)
    {
        SysTableLookup          sysTableLookup = SysTableLookup::newParameters(tablenum(InventTrans),_control);
        QueryBuildDataSource    inventTransQbds;
        Query                   query;// = element.initQuery();
        ;
    
    
        sysTableLookup.addLookupfield(fieldnum(InventTrans, TransRefId),
                                      true);
        inventTransQbds = query.dataSourceNo(1);
    
        inventTransQbds.addSortField(fieldnum(InventTrans,TransRefId));
    
        inventTransQbds.orderMode(OrderMode::GroupBy);
    
        sysTableLookup.parmUseLookupValue(false);
        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();
    }


  • Suggested answer
    xelifchemnitz Profile Picture
    5 on at
    RE: GroupBy on Lookup problem

    For everyone also facing this problem:

    You have to use

    sysTableLookup.parmUseLookupValue(false);

  • Community Member Profile Picture
    on at
    RE: GroupBy on Lookup problem

    I tried use addSelectionField instead of addSelectionField, effect is still the same. I tried use they together, also without success.

    I was looking in these tutorials, i didn't find anythink like that (Lookup with groupBy).

  • Suggested answer
    JII SAADUDDIN Profile Picture
    1,832 on at
    RE: GroupBy on Lookup problem

    Hi Maces, try open AOT > Forms/Classes > find "tutorial_" you have existing lookup for samples standard in dynamics ax for beginners or starters in development

  • Community Member Profile Picture
    on at
    RE: GroupBy on Lookup problem

    I'm afraid that sysTableLookup.addSelectionField(), does not work in AX 2009, i get error: class hasn't this method.

    It looks like it has been working since the AX 2012.

  • Community Member Profile Picture
    on at
    RE: GroupBy on Lookup problem

    Hello Crispin,

    Thanks for your answers.

    I tried create an AOT query, effect is the same.

    I noticed that the popup works with an empty field:
    1460.popup.PNG
    Then in queryBuildDataSource we also have:

    SELECT FIRSTFAST * FROM PriceSignListTable GROUP BY PriceSignListTable.PriceListVersion

    If there is any value in the field, group by not working:
    1460.popup.PNG
    QueryBuildDataSource is still the same.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,935 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,801 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans