Need a GetLast method


I have several uses cases where I want to get just the latest of an entity matching a search. It's very draining performance-wise with the available tools, for instance if I'm trying to get the most recent TrailerAttachment for a specific trailer ID, I have to:

  1. Do a Get => TrailerAttachment call with a short activeFrom limit (ie: 2 weeks);
  2. If no results are found, issue another Get => TrailerAttachment call with a longer limit (ie: 3 months);
  3. If no results are found, issue another Get => TrailerAttachment call with an even longer limit (ie: 1 year);
  4. Repeat until I have at least 1 match or I have reached the sensible time limit for my application;
  5. Whenever I have results from any pass above, I then have to filter them all and keep only the most recent.

This makes for a lot of unnecessary calls, and even worse it often means we (both Geotab and I) have to serialize/transfer/unserialize/filter tons of data that I will be discarding in the end. If I have to do this for 3000 trailers then it's unbearable.

What would help, is a GetLast method, I could call:

api.call('GetLast', {
typeName: 'TrailerAttachment,
search: {
trailerSearch: {
id: myTrailerId
}, function(res){...}, function(err){...}); 

Then I'm sure I will get one and only one entity (the one I'm actually looking for) without having to make several passes, Geotab's server and network resources are optimized and so are ours. 

Any comment? Any other way to achieve what I'm trying to do as it is now?

LP Papillon [d2go]

Please sign in to leave a comment.




I would suggest using GetFeed() for this kind of workflow.  You can review our documentation and some examples here.

Each record in your database's relevant table is provided a version number.  GetFeed() allows you to pull only entries after a specified version number, which means you will only be polling data entered since the last GetFeed() call.  After your first use of this method you can store the most recent versions, and then you can always pull in the latest data with one call.

Kaylan Mettus 0 votes

Hi Kaylan,

Some of these applications might benefit from GetFeed, yes, but not all, and some of the entities that would benefit are not supported by GetFeed. In this case, instead of me making a simple call to get the single latest TrailerAttachment object for a trailer or device, your solution implies that I have to create a local table and a process that regularly polls all TrailerAttachments objects fleetwide to replicate them on my side, just so I can then simply this query and get the latest object I am after. Again, there's some cases where it makes sense for us to fetch and store all of these objects, but it's not a drop-in replacement in all cases and I still think a GetLast method would be useful - to us and to you internally as well. Proof is there actually exists an (undocumented) GetLastDVIRLogs which is used internally by Geotab Drive - I suggest making it more globally available (GetLast => typeName 'DVIRLogs' or 'TrailerAttachment'), documented and supported.


LP Papillon [d2go] 1 vote

To clarify one thing, for your trailer example, TrailerAttachmentSearch works with GetFeed.  You can still specify an individual object and date range if needed.

To make a request for another method or for more objects to work with GetFeed(), please open a ticket with support so that we can submit a feature request.  You can reference this post in the ticket as well.

Kaylan Mettus 0 votes

Hi Ben Virkler, 

For DutyStatusLog, there is a search property called includeBoundaryLogs which you can set to true. This will return the previous and latest duty statuses after the date range specified. You can use this search parameter to find the latest DutyStatusLog. Set the fromDate and toDate to be for "right now". 


Hi LP, 

If you're trying to get the latest "active" shipment, you should be able to specify the fromDate to be for "right now", and it should return active shipments. Of course, if the latest shipment is no longer active, then this won't work. What Kaylan suggested is the only solution we have atm. You can submit a feature request for this if needed. 


Vik Sridhar 0 votes