Query class example in D365 F&O
☰Fullscreen
You can modify and create queries from code by using the query class. The following example depicts a query being created with the name MyCustTable
. It has only one data source custTable
, with two fields: AccountNum and CustGroup. Then, you need to add the CustGroup to the range in code, which the following sample code illustrates.

The following example shows the result in code:
internal final class MyCustTableQueryModifyInCode { /// <summary> /// Class entry point. The system will call this method when a designated menu /// is selected or when execution starts and this class is set as the startup class. /// </summary> /// <param name = "_args">The specified arguments.</param> public static void main(Args _args) { Query query = new Query('MyCustTable'); // using the existing query named MyCustTable QueryBuildDataSource qbds; QueryBuildRange qbr; qbds = query.dataSourceTable(tableNum(CustTable)); // finding data source for table CustTable qbr = qbds.addRange(fieldNum(CustTable, CustGroup)); // adding range on CustGroup to the data source. QueryRun queryRun = new QueryRun(query); while (queryRun.next()) { CustTable custTable = queryRun.get(tableNum(CustTable)); info(strFmt('%1, %2', custTable.AccountNum, custTable.CustGroup)); } } }
No Questions Data Available.
No Program Data.