Using the Query classes, to get the entire result set in 1 buffer, Dynamics AX X++

Problem Statement:

I have a need to be able to dynamically build a query in X++. I can do so and make it work ,  After sometime i realize that its taking too long to be completed.



   common = queryRun.get(tableName2Id('InventTable'));

The problem is that makes you think that it is the only way to iterate.

After R&D i came to know that the this.queryrun().next(); It runs on client, fetches records one by one.

By using queryRun.get() it gets the entire set of records. So as long as you use .next() once.

The get method will actually get every record returned from the query in a buffer.

Common c;



   c = queryRun.get(tableId);






   next c;


the above code will only hit to database at once and load query results into buffer and now we can iterate results in memory  for better performance.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s