Feature Rich
Rapid Application Development
Helping you or your customers
Manage their Business

Using List Trigger Codes

There are three events that can trigger code to be run on a list item:
  • New Item Code (new_code)
  • After Update Code (after_code)
  • Deletion Validation Code (del_valid)

These code blocks can be found under the Update Options when editing a list and apply to the items within that list.

The New Item Code will be run after a new item is created and the current object {COID} will be the object that was created.
The After Update Code will be run on an object after it has been updated and the current object {COID} will be the object that was updated.
The Deletion Validation code will be run immediately prior to an object being deleted and the current object {COID} will be the object that was updated.

The deletion validation code is a little different from the others as if it returns anything other than an empty result then the object will not be deleted and the returned value will be displayed to the user. This allows the code to check things such as permission or data integrity and return a message to the user stating why they could not delete the record. For this reason, it is a good idea to include the {RETURN()} command at the end of the code to ensure that only the intended text is returned.

The New Item Code and Deletion Validation Code will only be triggered following direct user intervention, not following a UDB command or another trigger.
This is very important as it means that if within one block of trigger code, another item is created, modified or deleted then the trigger code associated to that list will not be run. You therefore need to manage any chain of events yourself. It also prevents code from getting into a loop.

You can use the EXEC_AFT_NEW and EXEC_AFT_UPD commands to force the trigger code to run in code.

The best practice is to keep the trigger code as simple as possible, preferrably calling pre defined functions held elsewhere. This will allow those same functions to be called from other triggers.