Hi I have specific scenario, suppose if there are 5 tables, Table1, Table2, Table3, Table4, Table5.
Table2 has a relation with Table1, Table3 has a relation with Table2, Table4 has a relation with Table3 and Table5 has a relation with Table4
I have an AOT query with Table3 as primary DS, Table4 as child DS of Table3 and Table5 as child DS of Table4
Now my query is if I want to add table1 and Table2 to existing query using code, how is that possible? Because if I get the qbds of Table3 or Table5 in code and add Table1 to it, its giving me wrong results compared to the new query I built.
This is what I am doing:
QueryBuildDataSource qbds5= query.dataSourceTable(tableNum(Table5));
QueryBuildDataSource qbds2 = qbds5.addDataSource(tableNum(Table2));
qbds2.addlink(Table3, RecId, Table2,RefRecId)
QueryBuildDataSource qbds1 = qbds2.addDataSource(tableNum(Table1));
qbds1.addlink(Table2, RecId, Table1,RefRecId)
or
QueryBuildDataSource qbds3= query.dataSourceTable(tableNum(Table3));
QueryBuildDataSource qbds2 = qbds3.addDataSource(tableNum(Table2));
qbds2.addlink(Table3, RecId, Table2,RefRecId)
QueryBuildDataSource qbds1 = qbds2.addDataSource(tableNum(Table1));
qbds2.addlink(Table2, RecId, Table1,RefRecId)
Both are giving wrong data, Can any experts suggest what is the best way to do this, or if it is at all possible to do this using code? I am aware that I can do this by making changes to the existing AOT query or create new qry but I am particularly looking to do this using code or see how it can be done.
(Only way I can see doing this with code is add Table4 again and then table3, table2, Table1)