[Tips] Error checking find mode
This one recently caught us even though we've been aware of this case for a long time. It's pretty obscure so worth highlighting again.
When you script a find -- either using the controller or the foundset -- always check to see if find mode was entered before proceeding with your find logic. If you don't, you can inadvertently end up overwriting field values of the current record with your search criteria if entering find mode fails.
So instead of:
foundset.find()
foundset.id_page = obj.page.record.id_page
foundset.id_group = obj.group.id
foundset.id_version = obj.snapshot.id
var count = foundset.search()
Do this:
if (foundset.find()) {
foundset.id_page = obj.page.record.id_page
foundset.id_group = obj.group.id
foundset.id_version = obj.snapshot.id
var count = foundset.search()
}
controller.find() and foundset.find() return a boolean indicating if entering find mode was successful.
The question is: when does going into find mode fail? Basically anytime Servoy has unsaved changes. In our recent case it was probably bad data entry (entering alpha characters in a numeric field for example). To quote Paul Bakker, running "in 'autoSave = false' mode and there are unsaved changes" will also trip things up.
http://www.servoy.com/forum/viewtopic.php?t=10261#p51690
An extra note: according to Johann not using the error check when finding on foundsets derived from databaseManager.getFoundSet(...) is ok.
Comments (3)