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, ...
Suggested Answer

queryrun.next returns false in between iteration then gives true

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

HI, I have a piece of code 

int x =0;

do
{

var y = queryRun.next();
table1worker = queryrun.get(tableNum(table1), 1);
table2person = queryrun.get(tableNum(table2), 1);

x++;
} while(x < 45);


I know that I should be getting 46 records.
My main code should be --

do
{

table1worker = queryrun.get(tableNum(table1), 1);
table2person = queryrun.get(tableNum(table2), 1);

x++;
} while(queryrun.next());

I can see in the first piece that the 38th record returns false and the nfrom the 39th record it starts returning true..
I could see that table 1 worker is returned as no data selected for the 38th record..
The sql statement has cross joins..

What could be the possible reason for this.
Because of this my main loop is failing after 37 iterations and I am not able to get the other records

I have the same question (0)
  • GirishS Profile Picture
    27,843 Moderator on at

    Hi Sidharth_j,

    Can you elaborate your question?

    What you are trying to achieve from the above query.

    Also use rich formatting to insert code which makes it readable.

    Thanks,

    Girish S.

  • Sidharth_j Profile Picture
    Microsoft Employee on at

    So basically I want my main loop to run 46 times but since queryrun.next() returns false at the 38th record I am missing out on the last 8 records..

  • GirishS Profile Picture
    27,843 Moderator on at

    queryrun.next() returns false because there is only 37 record in your query.

    Try to add SysQuery::countTotal(queryRun) to get total number of record count in query and put it in info log.

    If the count returns 37 then there is only 37 records in a query.

    Thanks,

    Girish S.

  • Sidharth_j Profile Picture
    Microsoft Employee on at

    So we have used SysQuery::countLoops(queryRun) and that returns 46 and we are able to see the whole list of records but we have a constraint that we cant use sysquery function so we have to do it via a loop and while using the loop it breaks at 38th record and if you see the first piece of code.

    var y return false for the 38th record then it starts showing true for the 39th record onwards and we are able to see the records via the first piece of loop

  • GirishS Profile Picture
    27,843 Moderator on at

    Can you show me your full code?

    Also try use rich formatting option to insert code which will be easily readable.

    Thanks,

    Girish S.

  • Sidharth_j Profile Picture
    Microsoft Employee on at

    [DataSource]

    class table1

    {

         public void executeQuery()

        {

            

             var employmentDS = this.query().dataSourceTable(tableNum(tablex));

             employmentDS.clearRange(fieldNum(tablex), LegalEntity));

             this.populateWorkerData(table1_ds, LegalEntity);

        }

        private void populateWorkerData(FormDataSource dataSource, CompanyInfoRecId _legalEntity)

        {

            QueryRun queryRun = dataSource.queryRun();

            do
            {
                table1 worker = queryRun.get(tableNum(table1), 1);
                table2 person = queryRun.get(tableNum(table2), 1);
            } while(queryRun.next());

        }

    }



    Not able to use the rich txt formatting sorry. 
    This is my first post not sure how to do it..
    Ive tried to make it as readable as possible.

  • GirishS Profile Picture
    27,843 Moderator on at

    Can you explain me the functionality you are doing?

    You are adding a query run looping in the form execute query method which is not recommended, because the execute query will be called multiple times and each time your query run will be looped.

    If you explain your functionality then I will give you a suggestion based on that.

    Thanks,

    Girish S.

  • Sidharth_j Profile Picture
    Microsoft Employee on at

    We are trying to populate a gantt calendar cross company

    and we are trying to do it via query run.

    Normally we are able to do it using inline sql but we want to do it via queryrun as well

  • GirishS Profile Picture
    27,843 Moderator on at

    So why you are populating the data via form?

    Is there any specific reason?

    Thanks,

    Girish S.

  • Sidharth_j Profile Picture
    Microsoft Employee on at

    So we need to populate the form with the data that we get from queryrun

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 March 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 658

#2
André Arnaud de Calavon Profile Picture

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

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 333 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans