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.

While(queryRun.Next())

{

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

}
The problem is that queryRun.next() 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.
Solution:


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;

if(queryRun.next())

{

   c = queryRun.get(tableId);

}

 

while(c)

{

   ....;

   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.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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