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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Why when i use $orderby parameter in my custom API GET request my results get filtered?

(3) ShareShare
ReportReport
Posted on by 6

I have a custom API in Business Central on the Item Ledger Entry, and I added a piece of code that generate a random hardcoded value for the systemModifiedAt field (some record were missing it).

The code works well without $orderby parameter (retrieve the right data) however as soon as i add the $orderby parameter i only get one record for the hardcoded values (the first one). Also the results pass from 41.87MB to 41.79MB showing that something get filter.

Any idea why does it behave as such?

Here the piece of code i have in Visual Studio in AL in the itemLedgerEntries API Page:

       }        trigger OnAfterGetRecord()        var            TempSystemModifiedAt: DateTime;        begin            // Check if the SystemModifiedAt field is empty (0DT represents empty date and time)            if Rec.SystemModifiedAt = 0DT then begin                // If it's empty, manually set the date and time components                TempSystemModifiedAt := CREATEDATETIME(20191231D, 080000.075T);                    TempSystemModifiedAt := TempSystemModifiedAt + Random(5555555); // Add random number to the TempSystemModifiedAt                    Rec.SystemModifiedAt := TempSystemModifiedAt;            end;        end;         }

Here the result I get when using the $orderby parameter: /enter

And here the result I get when not ordering: Screenshot 1: /enter

Screenshot 2: /enter

Please let me know if someone has some ideas or assumptions, ChatGdp has none or not the right one haha :)

I have the same question (0)
  • MS-01071154-0 Profile Picture
    6 on at
    Have you found an answer / solution to this problem? I want to order by the field orderDate via code (because it should be the default sort, a request from my customer). As soon as I do that, there are missing records, just like in your example here.
  • Suggested answer
    Suresh Kulla Profile Picture
    50,280 Super User 2026 Season 1 on at
    Why are you modifying the ModifiedAt ? and why can't you set the SourceTableView on your API Page.
  • Suggested answer
    YUN ZHU Profile Picture
    102,608 Super User 2026 Season 1 on at
    Hi, hope the following can give you some hints.
    Dynamics 365 Business Central: How to set and change the default sort order of a page
     
    Thanks.
    ZHU
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    23,136 Super User 2026 Season 1 on at

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 580 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 480 Super User 2026 Season 1

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 261 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans