General X++ Development
How do I add a join to a QueryBuildDataSource?
How do I add a join to a QueryBuildDataSource?
1 answer
Write an answerAdd the child datasource under the parent datasource, set the join mode, and define the link if you are not using metadata relations.
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.
Know the solution?
Sign in to contribute an answer and build your community reputation.
Sign in to answer