Skip to main content

Posts

Showing posts with the label Queries

Building query AND using query object in X++

Create and add datasource with range in X++ // Code using X++ to build the query Query query; QueryRun queryRun; QueryBuildDataSource qbds; ProjTable ProjTable; ; query = new Query(); // Add a datasource to the query qbds = query.addDataSource(tableNum(ProjTable)); // Add a range to the newly added datasource. qbds.addRange(fieldNum(ProjTable, ProjId)).value( "00403_1036..00412_1036" ); queryRun = new QueryRun(query); while(queryRun.next()) { projTable = queryRun.get(tableNum(ProjTable)); info(projTable.ProjId + ", " + ProjTable.Name); } Use query object to retrieve AOT query // Code using a query string static void UseAOTQuery(Args _args) { Query query; QueryRun queryRun; QueryBuildDataSource qbds; QueryBuildRange qbr; ProjTable p rojTable ; qu...

Count records in Query Vs Cound Loops in Query

Sometime we do need to know the number of records fetching through X++ query and this can be achieved by SysQuery::CountRecords(QueryRun) function.  This function works similar to this X++ logic; ProjTable   projTable;     select count(RecId) from projTable; info(strFmt("%1 total records", projTable.RecId)); // total tecords 1130 Lets see with X++ query; static void CountProjTableRecords(Args _args) {           Query                           query = new Query();          QueryRun                     queryRun;          QueryBuildDataSource qbd;          qbd = query.addDataSource(tablenum(ProjTable));         queryRun = new QueryRun(query);         info(strfmt("Total Records in Query...

AOT and X++ queries and ranges in AX 2012

Let's say we have a query in AOT  \Queries\ProjTable And now we want to add more datasources into this query's parent datasource (ProjTable) and some ranges etc. Let's assume we have a class (SRS report data provider class or a dialog class) which is using above query and during processing in this class we want to add more datasources and so on. I created a SRS report data provider class for this example; Class declaration [     SRSReportQueryAttribute ( querystr (MarginAnalysisReportV2Sw)),     SRSReportParameterAttribute( classstr (MarginAnalysisReportContractV2Sw)) ] public class MarginAnalysisReportDPV2Sw extends SRSReportDataProviderBase {     Query                       query;     TempTable               tempTable;     RecordInsertList       recordInsertListTmpTable;    ...