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 :
Microsoft Dynamics AX (Archived)

QueryBuildDataSource SortOrder

(0) ShareShare
ReportReport
Posted on by


Hello everyone,

I recently was using the query builder classes and wanted to see the sorting managed.

I found that when using the SortOrder static method there was no difference in direction when specifying Descending.

Does anyone know why in this block of code the sort order does not matter?

Here is a simple code sample you can run in a job.

static void Cyborg3QueryBuild2(Args _args)
{
    Query   query;
    QueryRun    qr;
    QueryBuildDataSource    qbds;
    QueryBuildRange qbr;
    VendTable   vendTable;
    
    query = new query();
    qbds = query.addDataSource(tableNum(vendTable));
    qbr =   qbds.addRange(fieldNum(vendTable, VendGroup));   
    qbr.value('10');

//here is the line where I thought I could control the sort direction
qbds.addSortField(fieldNum(vendTable, AccountNum),SortOrder::Ascending); qr = new QueryRun(query); if(qr.prompt()) { while(qr.next()) { vendTable = qr.get(tableNum(vendTable)); info( vendTable.AccountNum); } } }


*This post is locked for comments

I have the same question (0)
  • Verified answer
    Sohaib Cheema Profile Picture
    49,677 Super User 2026 Season 1 on at

    Hi Keith,

    This is because of syslastValue. it is always getting previously used query, which was saved in Last Value.

    you can solve this by introducing one line of code, immediately after query run.

     qr = new QueryRun(query);
        qr.saveUserSetup(false);//add this new line in your code.



  • Community Member Profile Picture
    on at

    Thanks Sohaib.  I did try to find this answer but wasn't lucky. As always I appreciate the response.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans