KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: All about Triggers
PRODUCT: 4D | VERSION: | PLATFORM:
Published On: October 15, 1999

Triggers were introduced with 4D v6. A trigger is a method attached to a table. You cannot call a trigger: it is automatically invoked by one of the following events:


  • Adding a new record
  • Deleting a record
  • Modifying a record
  • Loading a record


Notes about triggers:

  • Triggers allow you to enforce actions in Custom Menus and User mode.
  • A trigger is a method associated with one specific table.
  • A trigger is at the engine level of 4D.
  • A trigger runs on the server in client/server mode, therefore it cannot see the process variable table of the client.
  • Triggers run in their own tables and should not modify records on other tables.
    If you trace a trigger (in client/server mode) it will be traced on the server not the client.


Uses for triggers:

  • Enforcing data integrity and data formatting.
  • Enforcing/maintaining relational data integrity.
  • Creating compound indexes.
  • Encrypting/decrypting data.
  • BLOB management.
  • Custom access privileges.
  • Database audit trails.
  • Distributed systems and replication.
  • Data synchronization.

Be aware that if you are in a trigger and you need to execute a query on the same table you will be unable to change the current selection. This is because you are in the process of saving the record. If you attempt to change the current selection you will crash. Therefore you need to use SET QUERY DESTINATION.