web
You’re offline. This is a read only version of the page.
close
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

}

/>

I have the same question (0)
  • Community Member Profile Picture
    on at

    Please help me reslove the issue.

  • Martin Dráb Profile Picture
    237,961 Most Valuable Professional on at

    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

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

  • ergun sahin Profile Picture
    8,826 Moderator on at

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

  • Abdulaziz Albloshi Profile Picture
    365 on at

    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.

  • Community Member Profile Picture
    on at

    No, it doesn't.

  • Community Member Profile Picture
    on at

    Okay, let me try that.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 592 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 478 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 305 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans