web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

QueryRun.next() only looping once, even though SysQueryRun::countLoops(queryRun) shows the total number of loops = 3

(2) ShareShare
ReportReport
Posted on by Microsoft Employee

I am currently trying to loop through the data being pulled by the QueryRun object I made. The query generated by the filters/ranges I set does pull the correct rows when I translated the query to SQL. I also used SysQueryRun::countLoops(queryRun) to see how many rows were in the queryRun obj, and it said 3 (which is how many I excepted and how many where returned by the SQL query). 

However, when I debug and enter the while(queryRun.next()) loop, it only loops once before queryRun.next() returns false. Therefore, only one row is processed and returned. Is there another way to grab the rows that are tied to the queryRun obj?

I have the same question (0)
  • Blue Wang Profile Picture
    Microsoft Employee on at

    HI Apndt3,

    Is it easy to share your code?

    While(queryRun.Next())
    {
        common = queryRun.get(tableId);
    }

    You can try to transform the code, although they mean the same.

    if(queryRun.next())
    {
       common = queryRun.get(tableId);
    }
    
    while(common)
    {
       ...;
       next common;
    }

  • apndt3 Profile Picture
    Microsoft Employee on at

    Thank you for your response!

    The original code I had was:

    while (queryRun.next())

    {

    table1 = queryRun.get(tableId1); //main salesTable

    table2 = queryRun.get(tableId2);

    table3 = queryRun.get(tableId3);

    salesLine = salesLine::findId(table3);

    ...

    }

    I did try what you suggested a few days ago, but get this error :

    Stack trace: Cannot call the NEXT command at this point. Either: (a) the buffer was initiated on the server, (b) SELECT was never called, (c) SELECT was called but no more rows exists, or (d) data was assigned using the data() method.

    I tried just using one table and calling the other queryRun.gets in the while loop, but <next table1> returned false by the second iteration.

  • Sergei Minozhenko Profile Picture
    23,097 on at

    Hi apndt3,

    You mentioned SysQueryRun::countLoops method. Is class name SysQueryRun or SysQuery? If you remove this call, does while(queryRun.next()) loop work correctly?

  • apndt3 Profile Picture
    Microsoft Employee on at

    Unfortunately it doesn't. I had added the SysQueryRun call as an attempt to see whether the queryRun object was matching up to the SQL statement produced and actually holding more than a single line. The issue with the loop had been happening prior to adding the call

  • Sergei Minozhenko Profile Picture
    23,097 on at

    Hi apndt3,

    Could you, please, share you query object is created (query structure)?

  • apndt3 Profile Picture
    Microsoft Employee on at

    Thank you so much for your responses, but I just got it working! Thanks for you time I really appreciate it

  • RT-17121508-0 Profile Picture
    6 on at
    @apndt3 : How did you fix this issue ? I am facing the same. Many thanks in advance!!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 692

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 532 Super User 2026 Season 1

#3
CP04-islander Profile Picture

CP04-islander 478

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans