Skip to main content

Notifications

Announcements

No record found.

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

Get group by field in query run

Posted on by Microsoft Employee

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
    Community Member Microsoft Employee on at
    RE: Get group by field in query run

    Okay, let me try that.

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

    No, it doesn't.

  • Abdulaziz Albloshi Profile Picture
    Abdulaziz Albloshi 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
    ergun sahin 8,812 Super User 2024 Season 1 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
    Community Member Microsoft Employee 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
    Martin Dráb 230,235 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
    Community Member Microsoft Employee 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans