I just ran into a very big issue that took me hours to troubleshoot.
After developing for many hours, I had forgotten a change I had made that caused a big problem.
When a tab panel is showing a related form and the fields on that form come from a third table (e.g. Your current form is a list view for T1, tab panel shows list view from T2 and fields shown on form tied to T2 are from T3) you can’t rely on the allow creation of a relationship and simply set a field value and have a record created.
I have been educated in that I need to explicitly create the related record. This was fine and my code was working in the following the form.
//Explicitly create the related record in the subs database
mag_group_membership_to_mag_subs.newRecord();
mag_group_membership_to_mag_subs.subs_gid = pn_gid;
This works fine when the PK for the table on the left side is Servoy managed (servoy seq as opposed to db identity) and is in Sync.
However, this creates an error when it is set to db identity, which is required for web databases that also have php code running them. You receive a “Cannot convert null to an object.” error.
After thinking things through I thought that Servoy needed to retrieve the PK from the DB so I tried adding a controller.saveData().
controller.saveData()
application.output(controller.copyRecord());
//Explicitly create the related record in the subs database
mag_group_membership_to_mag_subs.newRecord();
mag_group_membership_to_mag_subs.subs_gid = pn_gid;
Using the application.output(controller.copyRecord()); shows the results that Servoy does see the PK. However, now you sometimes get an error of undefined value or the method will complete but the explicitly created record does not exist and was never created.
I also noticed that if you are allowing Servoy to manage the pk, then using the controller.saveData() prior to creating the related records will break the whole operation. Is this because Servoy committs and looses the PK it would have used to create the related record?
Is this a bug? Shouldn’t Servoy be able to create related records with db managed PK’s? I’m assuming the correct action, prior to creating a related record with a db managed key, is to save the data.
This is a pretty critical issue for systems where there is both a web front end and Servoy is also being used for admin purposes. Anyone hit this issue?