Triggers are mechanisms that allow to perform a flow of actions when a given event occurs. For instance, triggers allow to define a flow of actions that will be executed after a record is updated in the database, or when a user clicks a form button in the user interface.
The context of a trigger is the point in the application where the trigger is activated. There are three types of trigger contexts possible to define in Genio: Table, Form, and Menu. For each type of context, a set of concrete objects and events are available to be observed, as shown in Table 1.
Context | Object | Event | Parameters | Base table |
---|---|---|---|---|
Table | Record | Before update | Table | The specified table. |
Table | Record | Before update | Table | The specified table. |
Table | Record | Before insert | Table | The specified table. |
Table | Record | Before eliminate | Table | The specified table. |
Table | Record | Before duplicate | Table | The specified table. |
Table | Record | After update | Table | The specified table. |
Table | Record | After insert | Table | The specified table. |
Table | Record | After eliminate | Table | The specified table. |
Table | Record | After duplicate | Table | The specified table. |
Form | Form | Periodical | Form, Periodicity | The base table of the form. |
Form | Button | Click | Form, Form button | The base table of the form of the specified button. |
Menu | Button | Click | Menu continuation | - |
Table 1. Types of trigger contexts.
When these events occur, triggers observing them will evaluate whether the defined flow of actions should be executed or not. There are different mechanisms that can be used to conditionally execute the actions of triggers, as shown in Table 2.
Condition | Description | Example |
---|---|---|
Expression | An expression that will be evaluated at runtime. The actions of the trigger are executed if the expression evaluates to true . |
[INCID->ESTADO] == "FE" |
Permission | A role that the user that triggered the event must have. | Administrator |
Table 2. Types of trigger conditions.
At runtime, each one of theses conditions will be evaluated. All must evaluated to true
in order for the flow of actions of the trigger to be executed. A condition is ignored if it is not defined.
As discussed, triggers allow to specify a flow of actions. This support this, the order in which the actions are specified is the order in which they will be executed. Table 3 shows a summary of the actions that are currently offered by Genio.
Action | Description | Necessary context |
---|---|---|
Update the value of a field | Updates the value of a field with the value computed by an expression. | Table or Form or Menu |
Update formulas | Recalculates the computed fields of a record. | Table or Form or Menu |
Save | Saves the form and navigates to the previous page. | Form |
Save without leaving | Saves the form (applies the changes). | Form |
Internal import | Performs an internal import. | Table or Form or Menu |
Reload the page | Reloads the page. | Form or Menu |
Reload a control | Reloads a control of the form. | Form |
Table 3. Types of trigger actions.
The "Update the value of a field" action updates the value of the specified field with the value computed by the provided expression. This action requires four parameters, as shown in Table 4.
Parameter | Description |
---|---|
Table | The table to be updated. |
Table field | The target table field. |
Formula | The expression to be evaluated at runtime to compute the value of the field. |
Update formulas | Whether or not to update the formulas of the affected rows after this operation. |
Table 4. Definition of the "Update the value of a field" action.
To better understand how Genio determines the rows that will be affected by this action, consider the example illustrated by Figure 1 and a trigger based on the "After update" event of the table "District".
Figure 1. Illustration of the running example.
The execution of the action will change depending on the relation of the trigger's base table to the table of the action's target field, as shown in Table 5.
Target table | Target table (example) | Affected Rows |
---|---|---|
Parent | COUNTRY | 1 row, referenced by the main row. |
Self | DISTRICT | 1 row, the main row. |
Child | CITY | N rows, all the child rows of the main row. |
Table 5. Summary of the affected rows of the "Update the value of a field" action.
The "Update formulas" action recalculates the computed fields of a given set of rows. The set of rows to affect is determined in the same manner as previously shown in Table 5. This action requires one parameter, as shown in Table 6.
Parameter | Description |
---|---|
Table | The table to be updated. |
Table 6. Definition of the "Update formulas" action.
The "Save" action is the same action that is executed when users click the "Save" button in forms. Now, available as an action of a trigger, it is possible to chain it with other actions.