Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

SetCurrentKey

Posted on by 3,027

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

  • subrata.bauri Profile Picture
    subrata.bauri 1,112 on at
    RE: SetCurrentKey

    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.

  • Suggested answer
    Stefano Demiliani Profile Picture
    Stefano Demiliani 37,162 Most Valuable Professional on at
    RE: SetCurrentKey

    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.

  • jsshivalik Profile Picture
    jsshivalik 3,027 on at
    RE: SetCurrentKey

    Hi Stefano

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

    Thanks

  • Suggested answer
    RockwithNav Profile Picture
    RockwithNav 6,562 on at
    RE: SetCurrentKey

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

    Stefano explained how to use either of them!!

  • subrata.bauri Profile Picture
    subrata.bauri 1,112 on at
    RE: SetCurrentKey

    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
    Stefano Demiliani Profile Picture
    Stefano Demiliani 37,162 Most Valuable Professional on at
    RE: SetCurrentKey

    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.

  • jsshivalik Profile Picture
    jsshivalik 3,027 on at
    RE: SetCurrentKey

    Hi

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

    Thanks

  • subrata.bauri Profile Picture
    subrata.bauri 1,112 on at
    RE: SetCurrentKey

    Hi,

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

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans