update related record

What is the best way to update a related record?
I have built a sequencer using a ‘pick’ table (id_seq) and two scripts (GetNextObjID and IncreaseNextObjID). I’m using this technique, because i have to know the next id before inserting a new record. In the table ‘id_seq’ i have the fields obj_type_id, next_id, min_id, max_id, and increment. This way i can have a dedicated id range for every object type i have in my db (e.g., product, membership,…).
To fetch the next id i just use a simple select statment. However, I don’t know the best way to increase the value of next_id after the record has been inserted.

I tried the following:

forms.id_seq.controller.find();
forms.id_seq.obj_type_id = globals.gCurrObjTypeID;
form.id_seq.controller.search( false, false);
NextObjID = next_id;
Increment = increment;
forms.id_seq.next_id = NextObjID + Increment;

This only works when id_seq is the currently shown form. Otherwise the search doesn’t seem to work. Why that? Would there be a smarter way to do this, e.g. involving a relation?

Thanks!

PS: obj_type_id is the PK of the table, so the search should always return just one record.

I have modified my IncNextObjID script a bit and now it seems to work. Before I used loadAllRecords() to start with, I noticed that it never worked the first time i ran the script . However, as soon as I got to the loadAllRecords() inside the if clause for the first time it worked fine from then on. So I just tried loading all records to start with.
I’m not sure why this was happening. Is there a explanation?

controller.loadAllRecords();
controller.find()
obj_type_id = globals.gCurrObjTypeID;
controller.search( true, false);
if ( controller.getMaxRecordIndex() == 1 )
{
	var 	NextObjID = next_id + increment;
	next_id = NextObjID;
	controller.loadAllRecords();
}
else
{
	plugins.dialogs.showErrorDialog( 'Achtung',  'Error 3001: found ' + controller.getMaxRecordIndex() + ' recs' ,  'OK');
};

yes that is a bug in the final of 1.2 it is already fixed in the 2.0 rc releases