Skip to main content

Notifications

Microsoft Dynamics AX forum
Answered

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")));

  • Verified answer
    Vilmos Kintera Profile Picture
    Vilmos Kintera 46,147 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 227,979 Super User 2024 Season 2 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.

Helpful resources

Quick Links

Dynamics 365 Community Update

Welcome to the inaugural Community Platform Update. As part of our commitment to…

Dynamics 365 Community Newsletter - August 2024

Catch up on the latest D365 Community news

Community Spotlight of the Month

Kudos to Mohana Yadav!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,142 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 227,979 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans