| **Navigation:**  [[welcome to my product .htm|User's Guide and Tutorials]] > The Dictionary > Dictionary Editor >====== Lesson 6 - Trigger Properties ====== | [[lesson 5 adding relationships.htm|{{btn_prev_n.gif|Previous page}}]][[welcome to my product .htm|{{btn_home_n.gif|Return to chapter overview}}]][[lesson 7 sql odbc and ado imports.htm|{{btn_next_n.gif|Next page}}]] | | || **Overview** Triggers are a mechanism for providing Clarion language support during database operations on a selected table. This support is added in the data dictionary, so all applications that reference this table will automatically contain the built-in support. Regarding SQL tables, the trigger support that is added here is considered to be //Client-Side//, and should not be confused with the //server-side// database triggers supported by many SQL engines. The uses of dictionary triggers are limited only to the developer's imagination. For more information regarding the uses of dictionary triggers, review the //Dictionary Triggers// topic found in the core help. This section simply describes how a trigger is added and maintained in the data dictionary. **To add a dictionary trigger to a selected table:** 1.In the DCT Explorer, double-click on the target table to open the Entity Browser. 2.In the Entity Browser, click on the //Triggers// folder, then press the **Add** button, or press the INSERT key. Alternatively, you can also right-click on the //Triggers// folder, and select **Add** **Triggers **from the popup menu. 3.In the //Trigger Properties// window, select from six different types of trigger entry points. Each name is self-explanatory: | Before Insert | After Insert | | Before Update | After Update | | Before Delete | After Delete | After a trigger type is added, you cannot select it again for the same table. 4.You can add trigger Data variables to use with the trigger source. Press the **Columns** tab to access the //Trigger Data// dialog, and press the **Add** button to add your data elements. These data elements are automatically included in the application's generated base class source file (Example: //myappBC0.clw//). They are only valid in the trigger type that they are created in, and are locally defined within the supporting trigger's derived method. 5.Enter your trigger source code in the **General** tab using the text control provided. Example trigger source: | **! After update trigger** | | ** IF ~ERRORCODE()** | | **   ****!Log insert** | | **   UPL:UpdRec = 'Pub ID: ('& PUB:PubID &')  was updated in Publisher on '&|** | | **                 FORMAT(TODAY(),@D1) &' at '&format(Clock(),@t3)** | | **   ACCESS:UpdLog.Insert()** | | **   ****! Change record in child file ( 1 <;--> 1 relationship)** | | **   PBI:PubID = PUB:PubID** | | **   IF ~Access:Pub_Info.TryFetch(PBI:PubID_Key)** | | **    !If record Change** | | **    PBI:Pr_info = CLIP(PBI:Pr_Info)&'<;13,10>Publisher '&clip(PUB:Pub_name) &|** | | **    ' in '& clip(PUB:City) & ' was updated on '&FORMAT(TODAY(),@d1)&'.'** | | **    Access:Pub_Info.Update()** | | **   END** | | ** END** | | ** ! End of trigger (After update)** | Two functions are accomplished here. After a record has been updated, a log entry is automatically entered into another table defined in the dictionary. After the log update, a child table is also updated with appropriate information. Although trigger source should be designed to be maintenance free, the source code that is entered can be modified in the Application Generator through the following Global embeds: {{triggerembeds.jpg|triggerembeds.jpg}} **Next: **[[lesson 7 sql odbc and ado imports.htm|Lesson 7 - SQL, ODBC, and ADO Imports]]