|Contents:||Main||Chapter||See Also:||Getting Started Manual||Advanced User Manual|
A trigger can also update a field in a file different than the one in which the edited field exists. To illustrate this, the previous example is extended to show how a separate Monitor file could be updated whenever a patient name is added or changed.
First of all, define this Monitor file using the Modify File Attributes option. The Monitor file's NAME field will contain the same value as the NAME field in the Patient file. A TIME field should be defined as a date/time data type; this field will contain the time the NAME field in the Patient file was added or changed. Use the Trigger option on the Utility Functions submenu to set up the trigger:
Select UTILITY OPTION: CROSS-REFERENCE A FIELD MODIFY WHAT FILE: PATIENT Select FIELD: NAME CURRENT CROSS-REFERENCES: 1 REGULAR 'B' INDEX OF FILE 2 TRIGGER OF THE 'DATE NAME CHANGED' FIELD OF THE PATIENT FILE Choose E (Edit)/D (Delete)/C (Create): CREATE WANT TO CREATE A NEW CROSS-REFERENCE FOR THIS FIELD? NO// YES CROSS-REFERENCE NUMBER: 3// Select TYPE OF INDEXING: REGULAR// TRIGGER WHEN THE 'NAME' field (#.01) OF THE 'PATIENT' File (#2) IS CHANGED, WHAT FIELD SHOULD BE 'TRIGGERED: NAME:MONITOR:TIME DO YOU WANT TO PERMIT ADDING A NEW 'MONITOR' ENTRY? NO// Y (YES) WELL THEN, DO YOU WANT TO **FORCE** ADDING A NEW ENTRY EVERY TIME? NO// Y (YES) ...OK --- SET LOGIC --- IN ANSWERING THE FOLLOWING QUESTION, 'TIME' CAN BE USED TO REFER TO THE EXISTING TRIGGERED FIELD VALUE. PLEASE ENTER AN EXPRESSION WHICH WILL BECOME THE VALUE OF THE 'TIME' field (#1 ) OF THE 'MONITOR' File (#16001) WHENEVER 'NAME' IS ENTERED OR CHANGED: NOW DO YOU WANT TO MAKE THE SETTING OF 'TIME' CONDITIONAL? NO// (NO) --- KILL LOGIC --- IN ANSWERING THE FOLLOWING QUESTION, 'TIME' CAN BE USED TO REFER TO THE EXISTING TRIGGERED FIELD VALUE. NOTE: 'OLD NAME' CAN BE USED TO REFER TO THE VALUE OF THE NAME FIELD BEFORE ITS CHANGE OR DELETION. PLEASE ENTER AN EXPRESSION WHICH WILL BECOME THE VALUE OF THE 'TIME' field (#1) OF THE 'MONITOR' File (#16001) WHENEVER 'NAME' IS CHANGED OR DELETED: @ ARE YOU SURE YOU WANT TO 'ADD A NEW ENTRY' WHEN THIS KILL LOGIC OCCURS? NO// Y (YES) DO YOU WANT TO MAKE THE DELETING OF 'TIME' CONDITIONAL? NO// (NO) WANT TO PROTECT THE 'TIME' FIELD, SO THAT IT CAN'T BE CHANGED BY THE 'ENTER & EDIT' ROUTINE? NO// (NO) NO-DELETION MESSAGE: DESCRIPTION: 1>The TIME field of the Monitor file will be triggered whenever 2>the NAME field of the Patient file is entered or changed. The 3>new value=NOW. A new entry in the Monitor file will be created 4>at the same time. If the NAME field in the Patient file is 5>deleted, TIME will be deleted. 6> ...CROSS-REFERENCE IS SET DO YOU WANT TO RUN THE CROSS-REFERENCE FOR EXISTING ENTRIES NOW? NO// (NO)
This example shows the extended pointer syntax used to specify a field in another file. The patient's NAME is used as a lookup value in the Monitor file. A new Monitor entry is created by the trigger. In a sense, this trigger really updates two fields in Monitor file, NAME and TIME.
An alternative extended pointer syntax is NAME IN MONITOR FILE:TIME. This syntax is exactly equivalent to NAME:MONITOR:TIME, and may better express the meaning of the extended syntax if you are a new user.
NOTE: The at-sign ("@") indicates that a field is to be deleted by the trigger.
Reviewed/Updated: March 4, 2007