When saving the subdepartment, the following code is executed. I first check to see if the subdepartment ID is set; if it is, this means I'm editing an existing subdepartment rather than creating a new one. In this case I'll just update the existing subdepartment resource, then move on to updating the supervisors table, which also uses the subdepartment ID to link the employees to it. There are no issues here because the subdepartment already exists in the database.
If the subdepartment ID is not set, then I first retrieve the next value for its primary key through the Oracle sequence we're using. I can then insert the new resource row, and again move on to updating the supervisor table.
Code: Select all
if (fields.SUBDEPARTID.value != null) {
resources.subdepartment.update();
} else {
resources.subdepartment_SEQ.fetch(); // get the next sub-department ID from the Oracle sequence
resources.subdepartment.insert();
}
tables.subdepartment_supervisors.updateTable();
I encountered this same issue in other forms, and to get a around the problem I would use DatabaseServices to insert the new subdepartment, execute that statement, then be able to use .updateTable() on whatever tables needed it. This works but it's not exactly elegant since I end up needing to maintain SQL outside of a resource and set all the parameters for the insert, when the resource would normally take care of that for me.
Is there a better solution to this I haven't thought of?