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

Notifications

Announcements

No record found.

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

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
    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
    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,093 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
    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,093 on at

    Hi apndt3,

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

  • apndt3 Profile Picture
    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 584 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 499 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 254 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans