web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Join multiple table in Query in X++

(0) ShareShare
ReportReport
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

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

    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.

  • Verified answer
    Vilmos Kintera Profile Picture
    46,149 on at

    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.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans