web
You’re offline. This is a read only version of the page.
close
Skip to main content
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
    48,887 User Group Leader on at
    RE: QueryBuildDataSource SortOrder

    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
    RE: QueryBuildDataSource SortOrder

    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

Responsible AI policies

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

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#3
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans