In this video, we're going to learn how to configure database events and how to take them into account in the programming.
A trigger (or table method) is used to check on actions performed by the database engine on data:
- creation
- modification
- deletion.
In that sense, a trigger is a method like any other. It's simply the context in which it is executed that changes.
Like form events, database events must be checked so that 4D gives control to the trigger to execute.
We can enable any database event in the Table inspector.
You’ll find the “Edit” button at the bottom right, which allows creating the method to execute when the checked events occur.
The method is generally structured in the following manner:
Unlike a form method that is only executed during a display (or print), a trigger is executed regardless of how you access records:
- programming
- import/export
- SQL
- Web
- and so on.
The trigger has the advantage of being a mandatory passage point.
- Let's add a Date_Last_Modified field to the Interventions table
- We'll make it visible on the form
- And assign a value to it whenever we save a record:
Of course, this latest modification will also be valid when creating a record.
Let's try it out by performing a modification:
- If we change the intervention date
- Then save it and come back here, the modification date has in fact been assigned a value
- So the trigger works correctly.