I am on the latest version 9.10.021 (2), in this version when a line insert is performed in a detail form (gridview), the ID returned is zero.
If we do a sc_redir itself and reload the detail form once inserted, specifically in onAfterInsert after sc_commit_trans(), it will collect the ID that has been recorded in the Table, it is seen that it has been incremented and inserted correctly, but the user is seeing Unnecessary ‘reloads’ of the form every time you insert a row.
Also, the problem comes when you need to use this ID in onAfterInsert, for example to write it to another Table,
1st we will have to do a “SELECT LAST_INSERT_ID()” to collect the newly recorded key,
2nd carry out the processes with the recovered ID.
3rd then execute sc_commit_trans().
and 4th sc_redir to reload the form, because if the user wants to modify the row again, it has to have its ID, not a zero.
Let’s look at the following:
If the user wants to update the row, after having inserted it, and in our processes we need to use the ID of the row that is being modified, in an onValidate or onBeforeUpdate, this ID field will be at ZERO, we will not be able to search even in its Table, nor in external tables with a sql of the style: “SELECT field FROM Table WHERE ID = {ID}”, unless we had done everything indicated in the previous section (LAST_INSERT_ID()…,sc_commit_trans()…and sc_redir itself…).
Why doesn’t scriptcase do all this, simply reloading the ID field, with its new value, once inserted? The onAfterInsert event is very descriptive ‘After Insert’, well, if it has already been inserted, it means that a sc_commit_trans has already been processed or if there had been errors, we would not be allowed to be executing processes in onAfterInsert, the internal sc_rollback_trans of scripcase would have prevented us from reaching this event. I repeat again, what’s wrong with loading the ID field with the new key, once it has been successfully inserted?
Greetings