Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Join multiple table in Query in X++

Posted on by 385

Dear All

I have make make query using X++ join three table but desire result not showing 

Please help me and let me know is it ok ??

qbdsCustInvoiceJour = query3.addDataSource(tableNum(CustPackingSlipJour));
qbdsCustInvoiceJour.relations(true);
qbdsCustInvoiceJour.joinMode(JoinMode::InnerJoin);

qbdsCustTable=qbdsCustInvoiceJour.addDataSource(tableNum(CustTable));
qbdsCustTable.relations(true);
qbdsCustTable.joinMode(JoinMode::InnerJoin);

qbdsGatePassLine = qbdsCustInvoiceJour.addDataSource(tableNum(GatePassLine));
qbdsGatePassLine.relations(true);
qbdsGatePassLine.joinMode(JoinMode::NoExistsJoin);
qbdsGatePassLine.fields().addField(fieldNum(GatePassLine,InvoiceId));

qbdsCustInvoiceJour.fields().addField(fieldNum(CustPackingSlipJour,PackingSlipId));
qbdsCustInvoiceJour.fields().addField(fieldNum(CustPackingSlipJour,SalesId));
qbdsCustInvoiceJour.fields().addField(fieldNum(CustPackingSlipJour,InvoiceAccount));

qbdsCustTable.fields().addField(fieldNum(CustTable,AccountNum));
Customerqbr= qbdsCustTable.addRange(fieldNum(CustTable,CompanyChainId));
Customerqbr.value(queryValue(("GDN GP")));

*This post is locked for comments

  • Verified answer
    Vilmos Kintera Profile Picture
    Vilmos Kintera 46,149 on at
    RE: Join multiple table in Query in X++

    Also your query is wrong in a sense that you are doing addField calls, but AX automatically adds all fields for you. You only need to add specific fields, if you have cleared the field list beforehand.

    Also you should consider using SysQuery::findOrCreate* method as a good practice to avoid adding duplicate datasources, ranges, whatsoever in the future.

    Finally, check the generated query as Martin suggested in order to be sure the data you are expecting would show, like you are not missing records for the value you are trying to filter for, you are also in the correct legal entity (company), there are relations correctly defined between the tables, and finally exprimenting with the fetch mode.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    RE: Join multiple table in Query in X++

    Can you explain your problem, please? Fixing an unknown problem is quite difficult.

    I strongly recommend you look at the query you generated and compare it with what you intended. Call qbdsCustInvoiceJour.toString() to get the SQL-like query string. You'll probably need to add .fetchMode(QueryFetchMode::One2One) on the child data sources to see them there (or to restructure your query to use CustTable as the root datasource).

    By the way, make sure that your GatePassLine table has a corresponding relation.

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,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans