Join table A - B and A - C with Axapta query

Hi All,

I tried:

Query query = new Query();
QueryBuildDataSource qbds,qbds1,qbds2;
querybuildrange r;
;
qbds = query.addDataSource(tableNum(smaserviceordertable));
qbds1 = qbds.addDataSource(tableNum(b_repairjournal));
qbds1.relations(false);
qbds1.addLink(fieldNum(b_repairjournal,serviceorderid),fieldNum(smaserviceordertable,serviceorderid));
qbds2 = qbds1.addDataSource(tableNum(inventtable));
qbds2.relations(false);
qbds2.addLink(fieldNum(smaserviceordertable,itemid),fieldNum(inventtable,itemid));

info(qbds.toString());

Also I tried:

qbds2.addRange(fieldNum(inventtable,itemid)).value("( smaserviceordertable.itemid == inventtable.itemid )");

instead of :

qbds2.addLink(fieldNum(smaserviceordertable,itemid),fieldNum(inventtable,itemid));

It didn’t worked too.

That doesn’t works too:

Query query = new Query();
QueryBuildDataSource qbds,qbds1,qbds2;
querybuildrange r;
;
qbds = query.addDataSource(tableNum(smaserviceordertable));
qbds1 = qbds.addDataSource(tableNum(b_repairjournal));
qbds1.relations(false);
qbds1.addLink(fieldNum(b_repairjournal,serviceorderid),fieldNum(smaserviceordertable,serviceorderid));
qbds2 = qbds.addDataSource(tableNum(inventtable));
qbds2.relations(false);
qbds2.addLink(fieldNum(smaserviceordertable,itemid),fieldNum(inventtable,itemid));

info(qbds.toString());

What should I do? I know I can do it with using select - SQL but I should use query in this case.

Set fetchMode(QueryFetchMode::One2One) for both child datasources. Or join datasources in a sequence instead of a tree (e.g. Journal → Order → Item).

Thank you, your first suggestion is worked, but I couldn’t understand second one. Actually it’s not necessary after first worked but I just wondered… :slight_smile:

As I understand your query, you have an order as the root datasource and link two other datasource to it. I think you wouldn’t run into the problem if you used journal as the root table, link order to journal and link item to order - or in the opposite order (Item → Order → Journal).

I see…

Thank you,