web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Sorting using C/al

(0) ShareShare
ReportReport
Posted on by 1,392

Hello experts,

Question 1

i have the table with keys shown below :

7485.Capture.PNG

How can i sort by STATUS using C/AL.?

Question 2 :


After sorting i want to show only Opened Status in timesheet header :

is this snippet of code correct ?

Time Sheet Header  OnOpenPage

TimeSheetLine.Setrange("TimeSheet No.","No."); TimeSheetLine.SetCurrentKey(Answer Question1); IF (TimeSheetLine.findFirst) and (TimeSheetLine.Status = TimeSheetLine.Status::open)Then FirstElemenet := TimeSheetLine."TimeSheet No."; IF (TimeSheetLine.findLast) and (TimeSheetLine.Status = TimeSheetLine.Status::open)Then LastElemenet := TimeSheetLine."TimeSheet No."; SetFilter("No.", '%1..%2, FirstElemenet, LastElemenet);

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    Add a new key with only field Status and then use that in SETCURRENTKEY, before the SETRANGE so your code should look like the below

    TimeSheetLine.RESET;

    TimeSheetLine.SETCURRENTKEY(Status);

    TimeSheetLine.SETRANGE("Time Sheet No.","No.");

    TimeSheetLine.SETRANGE(Status,TimeSheetLine.Status::Open);

    IF TimeSheetLine.FINDSET THEN

    REPEAT

    /// Add your logic here

    UNTIL TimeSheetLine.NEXT = 0

  • MedInfoTech Profile Picture
    1,392 on at

    hello Suresh,

    Why i get this error in this Code

    ---------------------------
    Microsoft Dynamics NAV Development Environment
    ---------------------------
    A variable is expected. For example :

    MyVar
    Customer.Name
    ---------------------------
    OK
    ---------------------------

    TimeSheetLine.RESET;

    TimeSheetLine.SETCURRENTKEY(Status);

    TimeSheetLine.SETRANGE(TimeSheetLine."Time Sheet No.","No.");

    TimeSheetLine.SETRANGE(TimeSheetLine.Status,TimeSheetLine.Status::Open);

    IF TimeSheetLine.FINDSET THEN

     REPEAT

      EXIT(TSHeader."No.");

     UNTIL TimeSheetLine.NEXT = 0;

  • Suggested answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    Have you declared time sheet line and tsheader as variables ? If ou don't declare them and try to use them you will get that error

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans