General X++ Development

How do I add a join to a QueryBuildDataSource?

Asked by Sunny Vasty· Aug 13, 2026· 1 answers

How do I add a join to a QueryBuildDataSource?

SSunny Vasty75 reputation · answered Aug 13, 2026

Add the child datasource under the parent datasource, set the join mode, and define the link if you are not using metadata relations.

X++
QueryBuildDataSource custDs;
QueryBuildDataSource salesDs;

custDs = query.addDataSource(tableNum(CustTable));

salesDs = custDs.addDataSource(tableNum(SalesTable));
salesDs.relations(false);
salesDs.joinMode(JoinMode::InnerJoin);
salesDs.addLink(
    fieldNum(CustTable, AccountNum),
    fieldNum(SalesTable, CustAccount));

If a valid table relation already exists and it matches what you need, let the query use the relation instead of hardcoding another link.