D365FO – AX – Multiple tables join with Query AddLink syntax example

This example :

Query q;
QueryRun qr;
QueryBuildDataSource qbds;
QueryBuildDataSource qbds2;
QueryBuildDataSource qbds3;
QueryBuildRange qbr;

qbds = q.addDataSource(tableNum(CustPackingSlipJour));
qbr = qbds.addRange(fieldnum(CustPackingSlipJour, StatusExportDDTRhiagERA));
qbr.value(QueryValue(NoYes::No));
qbr = qbds.addRange(fieldnum(CustPackingSlipJour, ReturnItemNum));
qbr.value(QueryValue(“”));

qbds3 = qbds.addDataSource(tableNum(EDIDocumentParametersERA));
qbds3.relations(false);
qbds3.joinMode(JoinMode::InnerJoin);
qbds3.fetchmode(QueryFetchMode::One2One);
qbds3.addLink(fieldnum(CustPackingSlipJour, OrderAccount),fieldnum(EDIDocumentParametersERA, CustAccount));

qbds2 = qbds.addDataSource(tableNum(InterfaceWMSParameterERA));
qbds2.relations(false);
qbds2.joinMode(JoinMode::InnerJoin);
qbds2.fetchmode(QueryFetchMode::One2One);
qbds2.addLink(fieldnum(CustPackingSlipJour, InventLocationId),fieldnum(InterfaceWMSParameterERA, IntInventLocationId));

 qr = new QueryRun(q);

  while (qr.next())

{

//Insert code here

}

Produces this SQL output:

SELECT *
FROM CustPackingSlipJour
WHERE (StatusExportDDTRhiagERA = 0 AND ReturnItemNum = ”)
JOIN EDIDocumentParametersERA
ON CustPackingSlipJour.OrderAccount = EDIDocumentParametersERA.CustAccount
JOIN InterfaceWMSParameterERA
ON CustPackingSlipJour.inventLocationId = InterfaceWMSParameterERA.IntInventLocationId

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo di WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...