Trigger Activation
Triggers can be activated by events originating from user actions, ProcScript statements, and external events (such as asynchronous interrupts).
A Uniface application is event-driven, so when an event occurs, the corresponding trigger is activated. The script in the trigger determines the subsequent action that occurs. If a trigger is not defined, it may have default behavior, and for some objects, default triggers are defined when the object is created.
Some ProcScript statements can activate triggers directory, but many other triggers are activated by user and system events. Generally, a trigger associated with such an event contains a ProcScript statement that implicitly activates other triggers. This can result in cascading processing.
Implicit Trigger Activation
Some events happen implicitly. For example, in Form components there are triggers available for checking the integrity of modified data when the user modifies a field. These triggers are loseFocus, leaveModifiedKey, and leaveModified.
Imagine what happens if a user modifies a key field and attempts to store the data without actually leaving the field. Uniface activates the data validation triggers before attempting to write the modified data back to the database. Superficially, there are two actions—modify and store. Behind the scenes, Uniface starts processing many more associated triggers:
- loseFocus, a field-level trigger
- leaveModifiedKey, an occurrence-level trigger
- leaveModified, an occurrence-level trigger
- store, a component-level trigger
- write (or writeUp), an occurrence-level trigger, for every occurrence of every entity in the form that needs updating in the database
- formatToDbms, a field-level trigger, for every field stored in encrypted format in the database
- delete (or deleteUp), an occurrence-level trigger, for every occurrence that has been removed
Much of the processing in each trigger can be handled with single ProcScript instructions such as store, write and delete. If all triggers in the process complete successfully, the user’s data is correctly stored in the database.
Cascading Processing
Consider the processing initiated by a ^STORE function in a Form component:
- The user clicks a button that activates the ^STORE function.
- Uniface activates the required data validation triggers (validate and validateKey) and event completion triggers (loseFocus, leaveModifiedKey, and leaveModified).
- When the validation and completion triggers successfully complete, Uniface activates the store trigger of the component.
- The store ProcScript
statement in the store trigger activates the
write trigger for every modified entity occurrence.
However, if the store statement had been omitted from the store trigger, the write trigger is not activated.
- The write ProcScript statement in the write trigger activates the formatToDbms trigger of each field.
- Data is passed to the database connector and stored in the database.