General X++ Development
How do I create a query dynamically in X++?
How do I create a query dynamically in X++?
1 answer
Write an answerBuild the query with Query and QueryBuildDataSource, then execute it with QueryRun.
Query query = new Query();
QueryBuildDataSource qbds;
qbds = query.addDataSource(tableNum(CustTable));
qbds.addRange(fieldNum(CustTable, CustGroup))
.value(queryValue('10'));
QueryRun queryRun = new QueryRun(query);
while (queryRun.next())
{
CustTable custTable = queryRun.get(tableNum(CustTable));
}Use this when the structure or filtering actually needs to change at runtime. If nothing is dynamic, a normal select is easier to read.
Know the solution?
Sign in to contribute an answer and build your community reputation.
Sign in to answer