Let's say we have an order table containing orders numbered 1, 2, 3 etc. This order number is in the column ‘id’ which is the primary key of the table. These numbers are always integers but they are not an identity. When adding an order to the table a bit of logic needs to determine the next available number. In principle this can be done with max(id) + 1. This works fine in the Windows GUI by putting this logic in a default procedure. It stops working however when an order with the same id is added by someone or something else simultaneously.
Say the highest order id is 10. Then I start creating a new order in the GUI which by the aforementioned logic gets order id 11.In the mean time another process inserts order 11 into the table. Then when I click the save button the GUI tries to save the new order with id 11 which is not available anymore and an error message follows.
I've tried to get around this by using an insert handler with the same max(id) + 1 logic. This eliminates the error message but after clicking the save button the GUI assumes the saved order is id 11 instead of 12 and thus selects the wrong record after saving.
The insert handler doesn't seem to tell the GUI the final id is 12 even though it specifically sets the id to 12 in its logic. The default procedure doesn't fire when clicking the save button so it can't set the correct id either.
How can I have the Windows GUI pick up on the correct final order id in such a way that it always selects the correct document id after saving? I know this can be fixed with an identity but if a data model change can be avoided that would have my preference for now.
Best answer by Anne BuitView original