Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Why the result is confused when I use the AddRange and AddSortField on RecId on RecId?

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I want to fetch a result set with some data sorted by RecId.

But the records are in large number, so I have to specific a range in every request.

So I write my code like this:

            Query query;
            QueryRun qrun;
            QueryBuildDataSource    qbds;
            QueryBuildRange qbr;
            query= new Query();
            qbds = query.addDataSource(tableId);
            qbr= qbds.addRange(fieldName2Id(tableId,"RecId"));
            qbr.value(">"+int642Str(from));
            qbds.addSortField(fieldName2Id(tableId,"RecId"));
            qrun = new QueryRun(query);


But the result is confused. The range is right, but the result set is not sorted.

How to resolve it?

*This post is locked for comments

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Why the result is confused when I use the AddRange and AddSortField on RecId on RecId?

    I did the qbds.toString() and get the correct way to troubleshoot issue.

    Thank you for your help.

  • Martin Dráb Profile Picture
    Martin Dráb 230,458 Most Valuable Professional on at
    RE: Why the result is confused when I use the AddRange and AddSortField on RecId on RecId?

    You're skipping an important step in debugging. You write code generating a query and then you look at results of the query, but you don't ever look at the query itself.

    Let's try it. When we see that the query is wrong, we don't have to waste time executing it, because it clearly won't give the right result. And understand what's wrong is the first step to resolving a problem.

    Either look at the qbds object in debugger, or use a little piece of code: info(qbds.toString()).

    By the way, such a filter by RecId is a very strange thing. Are you sure it's the right thing to do?

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans