Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

queryrun.next returns false in between iteration then gives true

Posted on by

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

  • GirishS Profile Picture
    GirishS 27,832 Super User 2024 Season 1 on at
    RE: queryrun.next returns false in between iteration then gives true

    Hi Sidharth_j,

    Is the issue got resolved?

    Thanks,

    Girish S.

  • Suggested answer
    GirishS Profile Picture
    GirishS 27,832 Super User 2024 Season 1 on at
    RE: queryrun.next returns false in between iteration then gives true

    Populating data to form at run time will effect your form performance.

    But I will give you a suggestion.

    Correct me if I am a wrong. You have build a query run which has list of tables and data - Based on that query run you need to loop through it and insert record in form datasource tables. If yes try the below steps.

    Try to add the code in the form init method. Also no need to get the query run from the form datasource. You are trying to get the query run from the form datasource which doesn't have data.

    Please see the below code.

    Public void init()
    {
        Table1  table1worker;
        Table2  table2person;
        Query   query = new Query();
        QueryBuildDataSource qbdsTable1, qbdsTable2;
        QueryRUn qRUn;
        super();
        qbdsTable1 = query.addDataSource(tableNum(Table1));
        qbdsTable2 = qbdsTable1.addDataSource(tablenum(Table2));
        qbdsTable2.relation(true);
        qRUn = new QueryRun(query);
        while(qRun.next())
        {
            table1worker = queryrun.get(tableNum(table1), 1);
            table2person = queryrun.get(tableNum(table2), 1);
            //assign the values to table field
            //insert your data in the form datasource tables.
        }
        
    }

    Thanks,

    Girish S.

  • Sidharth_j Profile Picture
    Sidharth_j on at
    RE: queryrun.next returns false in between iteration then gives true

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

  • GirishS Profile Picture
    GirishS 27,832 Super User 2024 Season 1 on at
    RE: queryrun.next returns false in between iteration then gives true

    So why you are populating the data via form?

    Is there any specific reason?

    Thanks,

    Girish S.

  • Sidharth_j Profile Picture
    Sidharth_j on at
    RE: queryrun.next returns false in between iteration then gives true

    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
    GirishS 27,832 Super User 2024 Season 1 on at
    RE: queryrun.next returns false in between iteration then gives true

    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
    Sidharth_j on at
    RE: queryrun.next returns false in between iteration then gives true

    [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
    GirishS 27,832 Super User 2024 Season 1 on at
    RE: queryrun.next returns false in between iteration then gives true

    Can you show me your full code?

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

    Thanks,

    Girish S.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans