How to get first record in a lookup datasource

I have a lookup datasource defined that maps an ID (int) to a String.

I also have a button that users can click to start editing a new row in the main datasource.

What I need to do is default the new record’s lookup value to be something meaningful. I.e. if I can get the first record in the lookup datasource and use the ID from that, then the new record will have a meaningful value set (and hence the lookup will display something real).

However, I HAVE to get the first record from the lookup datasource, I can’t, for example, simply assume that the first ID will be 0 or 1 because it differs for every user!

Only problem is that I don’t see anywhere a command to get the first record in a datasource (or any record). The best that I can see is to call fetchData and pass in a callback. But that assumes that I am loading up the whole result set into a JavaScript object.

All that I need is just the first record and the ID column from that record.

Is there a way to do this?

If this for a SelectItem, use defaultToFirstValue.

Otherwise, yes, use DataSource.fetchData() and just set endRow to 1 to avoid loading too many records.