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 NAV (Archived)

SetCurrentKey

(0) ShareShare
ReportReport
Posted on by 3,099

Hi

  In a report i have source table G/L Entry . In C/al Code i want sorting by Transaction in Ascending , Amount Descending . How it can be done

I am trying below code but it is not working


"G/L Entry".SETCURRENTKEY("Transaction No." , Amount);
"G/L Entry".SETASCENDING(Amount,Descending);

Thanks

*This post is locked for comments

I have the same question (0)
  • subrata.bauri Profile Picture
    1,144 on at

    Hi,

    Look into the base report 1. Customer - Top 10 List or 2. Inventory - Top 10 List.

  • jsshivalik Profile Picture
    3,099 on at

    Hi

    Could not get . secondly i have existing key on Transaction No only.

    Thanks

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    To order records, you need to:

    1) create a key that you want on the original table (or use an existing key)

    2) Use SETCURRENTKEY to use the selected key

    3) Use ASCENDING (or SETASCENDING) to set the key order

    For example:

    GLEntry.SETCURRENTKEY(GLEntry."Transaction No.");

    GLEntry.ASCENDING(TRUE);

    or

    GLEntry.SETCURRENTKEY(GLEntry."Transaction No.");

    GLEntry.SETASCENDING("Transaction No.",TRUE);

    For the Amount field, create a key that is "Transaction No." and Amount.

  • subrata.bauri Profile Picture
    1,144 on at

    I think there is no need to change the table definition when we could get the required result without any table change. The logic of the reports I've mentioned already will help to solve your issue.

  • Suggested answer
    RockwithNav Profile Picture
    8,959 Super User 2026 Season 1 on at

    SETASCENDING  OR ASCENDING are the only 2 keywords available for this.

    Stefano explained how to use either of them!!

  • jsshivalik Profile Picture
    3,099 on at

    Hi Stefano

      Isn't it possible without making any changes in the table

    Thanks

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    To sort for two fields you need to have these two fields in a key.

    An alterntive is to use code and "re-arrange" the records in code. Customer Top 10 list is an example but I suggest to use a more easy way. If you want to do that in code, first sort by Transaction No. (this is a standard key field and you can sort as I've suggested before).

    Then, loop through these sorted records, calculate the Amount field and use a temporary table to save the records in the right order.

    My suggestion: to be simple and use few lines of code, just add a new key to the Customer table. This is a quite common operation and more performant than using strange tricks.

  • subrata.bauri Profile Picture
    1,144 on at

    I think adding a key in the table can't be a good solution. I suggest just look into the two reports which i've mentioned already will serve your query.

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 NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans