Friday, July 1, 2011

Servoy TIP: How To Efficiently Create Records

This will create a new record as the first row, and will update the user interface. In most cases this is OK - however, there may be times when you want to add records and not update the user interface.
In this case you want to use the foundset object:
foundset.myField = "value";
Now that's all find and good - the record will be created and the user interface won't immediately change (until you call databaseManager.saveData()). This method is much faster when you're creating a bunch of records (or related records).

Now, something that I use when I'm using the second method is to grab a record object reference when I create the record - so I can choose to commit that newly created record right away. Here's the slightly modified code:
var record = foundset.getRecord(foundset.newRecord());
record.myField = "value";
Because we have a reference to the foundset record in the variable called "record" - we can tell the databaseManager to only save that one record (rather than all outstanding changes).

No comments:

Post a Comment