Microsoft_MVP_banner

Calculate timing in X++ operations [WinAPI::getTickCount()]

While reading some lengthy operations e.g. reading data from CSV files, fetching data in query and uploading data etc I wanted to know the time consuming in each opertion. This helped me to optimize my logic or query in making client-server calls. We can use following function to know about time consumption; int                 startTime, endTime; startTime = WinAPI::getTickCount(); [Perform X++ operations] endTime = WinAPI::getTickCount(); info(strFmt(‘It took %1 minutes’, ((endTime – startTime)/1000)/60)); Note: WinAPI::getTickCount() tells time in milliseconds you need to change accordingly as per your required unit.

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 projTable; query = new query(queryStr(ProjTable)); queryRun = new QueryRun(query); while (queryRun.next()) { projTable= queryRun.get(tableNum(ProjTable)); info (strFmt(“%1 – %2”, ProjTable.ProjId, ProjTable.Name)); } }

FaisalFareed@2025. All rights reserved

Design by T3chDesigns