When the solution matters

Tips...

Registration Documentation Knowledgebase Seminars / Training Partner Programs 4D Partner Central

Surveys

Now that we have written a method (LDB_TriggerMethod) that can assign a new number for a Primary Key, we need to have this method called by the actual Trigger for each database table. A Trigger is a 4D method that is attached to a table. The idea is, any time the record is created, modified, or deleted, a Trigger (i.e., a particular method) will fire. It doesn't matter where the action was taken (from the Web, from an ODBC client, from a regular 4D Client, etc.) - the Trigger always fires.

The first thing we need to do is to make sure that triggers are enabled for our two tables. Back in 4D's Design environment, bring up the Database Structure from the Tools menu. Double-click on the Surveys table to bring up the Table Properties palette.

screenshot

Click on the middle tab (circled in red) to bring up the Triggers section. Click the first two check boxes so that the trigger will fire on saving a new record, and on saving (modifying) an existing record. The click the Apply button.

You should repeat this same process for the "Answers" table.

The next thing to do is to actually create the Trigger for each of these tables. Bring up the 4D Explorer (from the Tools menu, choose Explorer). The third tab on the Explorer window is the Methods tab. Click that, and then expand the middle section ("Form Methods and Triggers") so you can see the list of Tables in the structure.

screenshot

With the "Answers" table highlighed, double-click on it (or click the Edit button, shown at the bottom center of the picture above). Create the new method, and type the following into it:

$0:=LDB_TriggerMethod (->[Answers]ID)

You will want to repeat the process, only this time for the Surveys table:

$0:=LDB_TriggerMethod(->[Surveys]ID)

Close all the Method windows in the Design environment.

 Previous Step  1 2 3 4 5 6  Next Step


International | Company | Contact 4D | Site Map | Privacy Policy | © 4D, Inc. 1995-2008 | Change font size: [A] [A] [A] | Print this page | 4D RSS Feeds