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:
- Code: Select all
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.