Friday, May 15, 2015

X++ Query in tree joining pattern

Generally X++ query can be created in a linear joining pattern for example

SalesTable - SalesLine - InventTable

However sometimes we would like write a query in a tree joining pattern as follows.




For that case, we can apply the code as the following way.

void TreeJoinExample()
{
    Query                   q;
    QueryBuildDataSource    qbdsSalesLine,
                            qbdsSalesTable,
                            qbdsInventTable;
    ;


    q = new Query();
    
    qbdsSalesLine = q.addDataSource(tableNum(SalesLine));

    qbdsSalesTable = qbdsSalesLine.addDataSource(tableNum(SalesTable));
    qbdsSalesTable.relations(false);
    qbdsSalesTable.addLink(fieldNum(SalesLine, SalesId), fieldNum(SalesTable, SalesId));
    qbdsSalesTable.fetchMode(queryFetchMode::One2One);

    qbdsInventTable = qbdsSalesLine.addDataSource(tableNum(InventTable));
    qbdsInventTable.relations(false);
    qbdsInventTable.addLink(fieldNum(SalesLine, ItemId), fieldNum(InventTable, ItemId));
    qbdsInventTable.fetchMode(queryFetchMode::One2One);
}

No comments:

Post a Comment