Using the basic objects in the query framework like Query, QueryBuildDataSource, QueryBuildFieldList, QueryBuildRange, QueryRun
static void Query(Args _args)
{
Query query = new Query(); //Creating a Object of Query Framework
QueryBuildDataSource queryBuild;
QueryBuildFieldList queryList;
QueryBuildRange qbr;
QueryRun qr;
CustTable custTable;
;
queryBuild = query.addDataSource(tableNum(CustTable));//Adding Datasource to Query
queryList = queryBuild.fields(); //Adding fields to Datasource of Query
queryList.addField(fieldNum(CustTable, AccountNum));
queryList.addField(fieldNum(CustTable, CustGroup)); // Adding the fields to querybuildfieldlist
queryList.addField(fieldNum(CustTable, Currency));
qbr = querybuild.addRange(fieldnum(CustTable,AccountNum)); // Adding Range to the Datasource of Query
qbr.value("1000..1300");//Adding value to the range of the Datasource
qr = new QueryRun(query);//Creating the Object of the Queryrun and passing the query object to excute the Query
while (qr.next())
{
custTable = qr.get(tableNum(CustTable)); // Getting the value of the Query in the relevant buffer
//custTable = qr.getNo(1); You can also write this commented code instead of the above one
info(strfmt("%1, %2, %3", custTable.AccountNum, custTable.CustGroup, custTable.Currency));
}
}
The Output will be as follows
As you all most be knowing that the CustTable in Dynamics AX is having so many entries but then also the Query is displaying only 8 records that is because we have applied the range on query and the value of the range in the query is 1000..1300 . It means that it will only fetch those records who have account numbers between 1000 and 1300
Keep on DAX- ing !!! Its fun
And watch out for more DAX-Ideas Coming up your way :)
No comments:
Post a Comment