update related record

Questions, tips and tricks and techniques for scripting in Servoy

update related record

Postby xtsr » Tue Feb 03, 2004 2:07 pm

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:
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.
xtsr
 
Posts: 101
Joined: Wed Jan 21, 2004 11:47 am

Postby xtsr » Wed Feb 04, 2004 9:47 am

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?

Code: Select all
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');
};
xtsr
 
Posts: 101
Joined: Wed Jan 21, 2004 11:47 am

Postby jcompagner » Wed Feb 04, 2004 11:17 pm

yes that is a bug in the final of 1.2 it is already fixed in the 2.0 rc releases
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet


Return to Methods

Who is online

Users browsing this forum: No registered users and 31 guests

cron