Get sorted TrackedEntityInstances

How can I get sorted tracked entity instances by Sdk.d2().trackedEntityModule() .trackedEntityInstances().withTrackedEntityAttributeValues()?

Hi Monjur,

the list of trackedEntityInstances cannot be sorted by using that method. Which property would you want to use to sort the list?

There is another method “d2.trackedEntityModule().trackedEntityInstanceQuery()” that automatically sorts the list by status (TEIs pending to sync appear in first place) and by lastUpdated. If you use this method remember to include “.offlineOnly()” to avoid unnecessary queries to the server.

Hope it helps

Thanks Victor. Long time no talk :slight_smile: .
The thing is, I would like to show the tracked entities in order first who enrolled recently, so that the user can find it easily without searching it by an attribute. The query would be offline only because I bind the user to download all entities at the beginning.

Yes, you are right. It is quite common to show the list of TEIs ordered by lastUpdated or last enrolled. We will add it in the SDK. In the meanwhile, you can use the “query” repository to get this order. It is important to use the “offlineOnly()” method; otherwise the API call will fail because no filters are provided.

Thanks again, Victor. The idea met my need for now, at least.