Troubles with counting

I have a table with 1 row…I use this table to store preferences, but also for counters.I use a simple method

var a = forms.menu.dossierprefix+utils.stringRight('000000'+(forms.menu.dossierlaatstenummer+1), 6);
forms.menu.dossierlaatstenummer+=1;
forms.menu.controller.saveData();

To create a number like 2007.000123.
dossierlaatstenummer is an integer. The reasion why I use this construction is becoz I want the user to give the freedom to change the counters and its format(for example at a beginning of a new year)

Occasionaly Servoy gives out double numbers. At first I thought that someone was tampering with the prefences and changing dossierlaatstenummer. So I put auditing on this table.
The results kinda confused me.
The log_data (see attach) shows that the dossierlaatstenummer goes from 1043->1044->1045 and then back to 1043->1044
Shouldn’t there be an entry in the log_data stating 1045->1043 ?

Anyone else had this kinda problem before? If there is better way to make a counter, i am always open for suggestions.

Thankx in advance.
Paulo

If you call this

var a = forms.menu.dossierprefix+utils.stringRight(‘000000’+(forms.menu.dossierlaatstenummer+1), 6);

how can you be 100% sure that this data is really accurate at the time? There might have been a broadcasting problem or whatever. What happens if you explicitly refresh the record from the db before you do your math and also acquire a lock, so no two clients can do the same thing at once?

You might want to take a look at this thread about invoicenumbers. It covers the same issue and has a solution.

http://forum.servoy.com/viewtopic.php?t=3705

Hope this helps.

ROCLASI:
You might want to take a look at this thread about invoicenumbers. It covers the same issue and has a solution.

http://forum.servoy.com/viewtopic.php?t=3705

Hope this helps.

Gonna use the solution mentioned in this thread. Thankx everyone.