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 :
Small and medium business | Business Central, N...
Suggested Answer

Filtering/sorting sales orders by LastModifiedDateTime has unexpected results

(5) ShareShare
ReportReport
Posted on by 18
Hey folks,
 
Just trying to debug an issue we have calling the Dynamics API for our app's BC integration.
 
We're trying to get all recently updates sales orders, using a call like this: https://api.businesscentral.dynamics.com/v2.0/<tenant-id>/<environment>/api/v2.0/companies(<company-id>)/salesOrders?$expand=SalesOrderLines&$filter=LastModifiedDateTime%20ge%202025-11-11T00%3A49%3A27.4600000Z&$orderBy=LastModifiedDateTime%20asc
 
For the most part, it works:
- Sales orders are returned in the order expected (last modified, ascending)
- No sales orders are returned with a last modified date LESS THAN the given date
 
The times are critical for us, as we use them to efficiently query, while ensuring that we don't miss any updates in BC.
 
HOWEVER
 
Sometimes, it doesn't work! And we get random results interleaved that violate the two invariants listed above. For example, here's the actual last modified dates pulled from that above request example.
 
2025-11-11T00:54:00.1830000Z,
2025-11-11T00:54:00.3700000Z,
2025-11-11T00:54:00.5170000Z,
2025-11-11T00:54:00.6430000Z,
2025-11-11T00:59:02.7170000Z,
2025-11-11T00:59:21.8200000Z,
2025-11-11T00:59:28.8000000Z,
2025-11-10T20:03:07.7170000Z,
2025-11-11T00:49:27.4600000Z,
2025-11-11T00:49:42.8830000Z,
2025-11-11T00:49:48.3000000Z,
2025-11-11T00:50:55.4430000Z,
 
You'll see that it's MOSTLY ascending. But then we get a record where it jumps back in time, and then continues from there again.
 
Can anyone explain this behaviour? We want to be able to figure out if there's a suitable workaround we can put in for this, but we can't do that unless we can pin down what the behaviour is. Another thing we've noticed, is that it seems like when we repeat the request again at a later date, the same collection of data becomes properly sorted, and there are no items that have a last modified date less than the requested one.

Thanks,
Michael
I have the same question (0)
  • Suggested answer
    OussamaSabbouh Profile Picture
    12,766 Super User 2026 Season 1 on at
    Hello,
     
    The issue happens because lastModifiedDateTime doesn’t guarantee perfectly ordered or consistent results during sync, data changes while you query.
    Fix: Use systemModifiedAt with systemId for reliable incremental sync:
    $orderby=systemModifiedAt,systemId
    $filter=systemModifiedAt gt {lastSeenTime}
       or (systemModifiedAt eq {lastSeenTime} and systemId gt {lastSeenSystemId})

    Or add a 1-minute overlap and deduplicate results.
     
    Regards,
    Oussama Sabbouh
  • Gerardo Rentería García Profile Picture
    25,555 Most Valuable Professional on at
    Hi
    Information is added about the statuses of the sales order.
    Best
    GR

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!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,926 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,158 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 533 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans