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)

How to group by with common table

(0) ShareShare
ReportReport
Posted on by 2,334

How to group by a common table with a specific field?

I'm getting a syntax error on (dt.fieldname2Id('BatchNo'))

Here's my code:

Common          common;
SysDictTable    dt;

dt        =    SysDictTable::newName('Table1');
common    =    dt.makeRecord();

while select count(RecId) from common
    group by common.(dt.fieldname2Id('BatchNo'))  //syntax Error here
    where common.(dt.fieldname2Id('flag'))==1
{ info(strFmt('%1',common.RecId));
}

*This post is locked for comments

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

    I'm not sure if anything like that is supported; I've never seen that. I would simply use the query framework (addGroupByField()).

  • MYGz Profile Picture
    2,334 on at

    Thanks Martin, that worked. I have been trying all sorts of things with Common, trying to treat it like a normal buffer table object as I'm unable to find any good documentation on Common and other generic types. Please share if you have any handy.

    Here's the working code:

        Common                  common;
        Query                   query;
        QueryBuildDataSource    qbds;
        QueryRun                queryRun;
        int                     row=0;
        TableId                 TableId;
    
        query   = new Query();
        TableId = tableName2id(TableName);
        qbds = query.addDataSource(TableId);
    
        qbds.addGroupByField(fieldname2Id(TableId,'BatchNo'));
        qbds.addRange(fieldName2id(TableId,'Flag')).value('1');
    
        queryRun = new QueryRun(query);
    
        while (queryRun.next())
        {
            row++;
        }
    
        info(int2str(row));


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 26

#2
imran ul haq Profile Picture

imran ul haq 8

#3
André Arnaud de Calavon Profile Picture

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

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans