I have a very simple form with 3 fields. When I use the event OnAfterInsert to do some some control, the record is not inserted the first time the form is used. If I use the same form a second time without leaving my browser, the record is inserted and the OnAfterInsert is executed.
If I leave me browser and open it again, I have the same issue. The first time I fill the form and post it, the record is not created in the database; If I fill it again and post it again, it works, and the OnAfterInsert also.
Very strange behavior .
Any idea or solution to fix this problem ?
Can you show your code in OnAfterinsert?
This behavior is only when the application is deployed localy or remotely (IOnternet). When it run in Scriptacse dev environment, it works well.
Here is the code.
sc_lookup(ds_personnes, “SELECT * FROM personnes
WHERE Nom = ‘{Nom}’ and Prenom = ‘{Prenom}’”);
if ({ds_personnes} === false)
{
echo “Access error. Message=”. {my_data_erro} ;
}
elseif (empty({ds_personnes}))
{
echo “Personne inconnue”;
}
else
{
echo “personne connue”;
}
I have also put 2 messages at the application level:
Message to confirm insert
Message after Insert
These messages are displayed and it looks like everything works fine; But in fact, the record is not inserted.
I also have tested with another browser and another workstation (client), same behavior. First time not work, second time ok.
I think you must use the macro sc_commit_trans() before you use other code in the event.
This macro has the objective to confirm a transaction set in the database.
In form applications, the events that can run this macro is dependent of the database update (onAfterInsert, onAfterUpdate, onAfterDelete, onBeforeInsert, onBeforeUpdate or onBeforeDelete), they are automatically protected through transaction control, since the connection is the same of the application.
If the user, in any of these events, use an application redirectioning (macro “sc_redir”) must before the redirect, use this macro to guarantee the transactions previously effected.
The problem is that for the first time the form is used it never goes in any event, so the sc_commit_trans() is never excecuted.
After lof of time spent to test and think, I have found the culprit. It’s the way I start my form to enter in insert mode. For that I used an event OnApplicationInit with this code:
sc_apl_conf(“form_personnes”,“start”,“new”);
Long time ago in Scriptacse V5 it has worked, but now it’s not the case. I have seen in the documentation that this macro must be use in an application to modify another one.
That’s what I have done and now it works. I have created a blank application which has this code in OnExecute:
sc_apl_conf(“form_personnes”,“start”,“new”);
sc_redir(form_personnes);
I hope this will help other users having the same issue
Anyway, thanks a lot for the time spent to help me.