HOW TO: Go to the last record

The fastest way to do that is to sort by primary key (or creationdate) descending. Alternatively you can use this method:

while(controller.recordIndex < controller.getMaxRecordIndex())
{
controller.recordIndex = controller.getMaxRecordIndex()
}

The latter will be much slower.

Hi Jan,

Interesting post !

I assume that you are saying that, in Servoy, sorting is going to be a faster process than a ‘while’ loop that has to run through all records to give you a result !?

But, why do you need to loop through the records to compare the current record with the maximum ?

I have set up a global method called ‘rec_last’ as follows :

currentcontroller.recordIndex = currentcontroller.getMaxRecordIndex()
forms.nav.elements.button_first.enabled = true
forms.nav.elements.button_last.enabled = false

Which moves me to the last record in the foundset without any comparison needing to be made !

Admittedly, I have not used this in any table where there are high volume records, but it seems pretty responsive and it works !

I also have a method : ‘rec_first’ as follows :

currentcontroller.recordIndex = 1
forms.nav.elements.button_first.enabled = false
forms.nav.elements.button_last.enabled = true

Which moves me to the first record in the foundset…

Am I doing something fundamentally wrong here and I just have not had the solution reach a point where it will not perform correctly !??

I am certainly interested in your take on this.

Regards
Harry

Hai Harry,

Your suggestion

currentcontroller.getMaxRecordIndex()

Gives you the last record of, indeed, the current controller.

The current controller however is limited to a max number of records of 200.

So, if you have something like 1000 records your last record would be number 200 and not number 1000.

That’s the reason behind the tip. The reason for the limitation is speeeeeeeeeeed (at least that’s what I have been told).

Hi Marcel,

Thankyou for the explanation.

Because of small volume record numbers that I have been experimenting with, I had no idea that there was a limitation in the record indexing function !

To all : Is there a list of this and any other limitations anywhere in the documentation so that I can familiarise myself with them ?

Cheers
Harry

Yep, Just play with it and download/read the manuals. On top of that… Use this forum!

Enjoy, you will love most of Servoy. What you don’t love just shout it out.

The guys from Servoy will help you…

Harry Catharell:
To all : Is there a list of this and any other limitations anywhere in the documentation so that I can familiarise myself with them ?

That depends on your definition of limitation. In my opinion it’s not a limitation but a feature. It just works differently than for example desktopdatabases and although Servoy has the ease of use of a desktop database it is a front-end to SQL systems where having a total record count at all times is not feasible.

I can’t make this work. Here’s the situation:

User performs a query of people and the found set contains 750 records. User sorts alphabetically by lastname. Then wants to start at everyone with lastname starting with “Z.” In FM, user would just click “go to last record.” How would this be accomplished in Servoy? (Obviously user could sort in descending order, but this isn’t preferred so let’s take it off the table)

I appreciate the superior caching abilities of Servoy, but we’ve got to find a way around this I think.

Thanks.

this i personally really don’t get this..
If you want to start wit Z, order then descending!!
That is just the way you should do it..

of course you can with 750 record jump fast to that last record with the code the code also listed above.

while(controller.recordIndex < controller.getMaxRecordIndex()) 
{ 
controller.recordIndex = controller.getMaxRecordIndex() 
}

Thanks Johan. I still think the 200 record caching is great, but I wonder if there could be a feature that allows us to request that Servoy caches all records, or to set manually the number of recs returned at a time.

If not, this is a lower priority at leas tfor me than other things. Thanks again.