General X++ Development

How do I convert an X++ select statement into a Query object?

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

How do I convert an X++ select statement into a Query object?

SSunny Vasty75 reputation · answered Aug 13, 2026

Rebuild the same query structure with Query, QueryBuildDataSource, ranges, and links.

X++
Query query = new Query();
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));

The important part is not the syntax change. It is making sure the Query object has the same datasources, joins, ranges, and ordering as the original select.