Using your editor, create a trigger definition file called
triggers.trg
with the following entry:+^CIF(acn=:,1) -delim="|" -pieces=2 -commands=SET,KILL -xecute="Do ^XNAMEinCIF"
^CIF
- specifies the global variable to which the trigger applies.acn=:
- in ZWRITE syntax, ":" specifies any value for the first subscript.1
- specifies that the trigger matches only if the second subscript is 1 (one).-xecute="Do ^XNAMEinCIF"
- provides code for GT.M to invoke to perform the trigger logic.
Execute a command like the following:
$ mupip trigger -triggerfile=triggers.trg
File triggers.trg, Line 1: ^CIF trigger added with index 1 ========================================= 1 triggers added 0 triggers deleted 0 trigger file entries not changed 0 triggers modified =========================================
Now, every SET and KILL operation on the global node ^CIF(:,1) executes the routine
XNAMEinCIF
.Using your editor, create an M routine called XNAMEinCIF.m with the following code:
XNAMEinCIF ; Triggered Update for XNAME change in ^CIF(:,1) Set oldxname=$Piece($ZTOLDval,"|",2) Set:'$Length(oldxname) oldxname=$zchar(254); old XNAME Kill ^XALPHA("A",oldxname,acn); remove any old xref ; Create a new cross reference if the command is a Set Do:$ZTRIggerop="S" . Set xname=$Piece($ZTVALue,"|",2) Set:'$Length(xname) xname=$zchar(254) ; new XNAME . Set^XALPHA("A",xname,acn)="" ; create new xref ;
![]() | Important |
---|---|
Within trigger context (Step 1 through 4) , if you modify the value of $ZTVALUE, GT.M commits it to the database at Step 5. GT.M executes all steps (0 through 5) as an Atomic (all or nothing) transactional unit. |