Hi all,
today we have the following mystery, not sure if this is a Servoy bug or some issue with my code…
Form has independent found set and is not showing on screen.
No scripts attahced to events on form.
All foundsets set to empty on startup.
Another independent found set form showing a specific record, showing on screen.
Run a script which:
Creates a record on the form.
Fills in data.
Saves.
The record is saved into the backend database, but save changes the foundset of the form!!! The form foundset sometimes becomes empty, other times it shows the record which was created prior to the one which I tried to save.
How can this be possible?
Anyone seen anything similar?
Developer 3.1.3_01, Mac OS.
Clients 3.1.3_01 Win XP.
Spoke to Jan Block about this issue.
This is my understanding of what happened:
The problem is that my form thinks it has a found set. Even when it is not showing in any related tabpanel.
Somewhere I have used
controller.loadRecords(query,args);
Later I use the same form to create records. If I add info to the record which makes it not be found by the query I used for the load, saving the record will make it disappear from the foundset. Since I’m using database generated keys, I rely on picking up the key of the record after I save it to link it to other records in the system…
controller.newRecord();
somefield = somevalue;
....
controller.saveDate();
return pk;
So I ended up with either the wrong pk or no pk at all!!! And chaos in my data.
The solution is to add
controller.loadAllRecords();
controller.loadRecords(foundset.unrelate());
before saving.
The last one does not cause a query on the DB, so I prefer it.
I do it before creting the new record.
Hope this helps someone avoid the same mistake.