Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Get group by field in query run

(0) ShareShare
ReportReport
Posted on by

Hi,

I have been trying to create a query where I am grouping it by item id from invent trans and batch id from inventDim. Now, when I try to get the table buffer of invent Dim, it is empty with no batch it present in it. Please help me with it.

</

qbds= query.addDataSource(tableNum(InventTrans));
qbdsInventDim = qbds.addDataSource(tableNum(InventDim));
qbdsInventDim.relations(true);
qbds.fetchMode(QueryFetchMode::One2One);
qbdsInventTable = qbds.addDataSource(tableNum(InventTable));
qbdsInventTable.relations(true);
qbds.fetchMode(QueryFetchMode::One2One);
qbdsEcoResCategory = qbdsInventTable.addDataSource(tableNum(EcoResProductCategory));
qbdsEcoResCategory.relations(true);
qbdsEcoResColor = qbdsInventDim.addDataSource(tableNum(EcoResColor));
qbdsEcoResColor.relations(true);
qbdsDSRCode = qbdsEcoResColor.addDataSource(tableNum(SLD_DSRCodeSetup));
qbdsDSRCode.relations(true);

qbds.addGroupByField(FieldNum(InventTrans, ItemId));
qbdsInventDim.addGroupByField(fieldNum(InventDim, InventBatchId));

queryRun = new QueryRun(query);

while(queryRun.next())
{
inventTransQuery = queryRun.get(tablenum(InventTrans));
InventDimQuery = queryRun.get(tablenum(InventDim)); // this line gives nothing in the buffer

}

/>

  • Community Member Profile Picture
    on at
    RE: Get group by field in query run

    Okay, let me try that.

  • Community Member Profile Picture
    on at
    RE: Get group by field in query run

    No, it doesn't.

  • Abdulaziz Albloshi Profile Picture
    365 on at
    RE: Get group by field in query run

    I would suggest to create a query and view first and than use that query/view in your code instead of adding the relations at run-time.

    This way you will have more visibility of records before start writing your code.

  • ergun sahin Profile Picture
    8,816 Moderator on at
    RE: Get group by field in query run

    Does the result change when you close the datasource codes other than InventTrans and InventDim and try to run the code?

  • Community Member Profile Picture
    on at
    RE: Get group by field in query run

    No InventBatchId is present against this record. Seems like there is something logically wrong.

  • Martin Dráb Profile Picture
    231,758 Most Valuable Professional on at
    RE: Get group by field in query run

    Your query returns just two fields - InventTrans.ItemId and InventDim.InventBatchId. All other fields will have default values.

    If InventBatchId is empty as well, maybe the inventory transaction simply doesn't have any associated batch ID.

    By the way, please use Insert > Insert Code (in the rich-formatting view) to paste source code.

    And which version of AX are you talking about? If AX 2012, you should choose Microsoft Dynamics AX 2012 in the version selector. If it's D365FO, you should ask in one of D365FO forums instead.

  • Community Member Profile Picture
    on at
    RE: Get group by field in query run

    Please help me reslove the issue.

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,884 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,758 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans