Triggers are chained or nested when a database update sets off more than one trigger. A nested trigger is a trigger set off by another trigger. GT.M assigns a nesting level to each nested trigger to up to 127 levels. While nested triggers are always Atomic with their triggering update GT.M gives each nested trigger a new trigger context rather than a part of the triggering update.A chained trigger is an arbitrary sequence of matching triggers for the same database update. Consider the following trigger definition entries:
+^Acct("ID") -commands=Set -xecute="Set ^Acct(1)=$ZTVALUE+1" +^Acct(sub=:) -command=Set -xecute="Set ^X($ZTVALUE)=sub"
This example sets off a chained sequence of two triggers and one nested trigger. On Set ^Acct("ID")=10
, GT.M chains together an arbitrary sequence of triggers for ^Acct("ID")
and ^Acct(sub:)
. It is possible for either the ^Acct(sub=:)
trigger or the ^Acct("ID")
trigger to execute first and the other to follow because the trigger execution sequence is arbitrary. Whenever GT.M invokes the trigger for ^Acct("ID")
, the Set ^Acct(1)=$ZTVALUE+1
code sets off the trigger for ^Acct(sub=:)
as a nested trigger.
Caution | |
---|---|
FIS recommends against using chained and nested triggers that potentially update the same piece of a global variable. You should always assess the significance of having chained triggers for a database update especially because of the arbitrary trigger execution order.The following table shows the stacking behavior of some Intrinsic Special Variables in chained and nested triggers. |
ISV |
Chained Triggers |
Nested Triggers |
---|---|---|
$REFERENCE |
Shared |
Stacked |
$TEST |
Stacked |
Stacked |
$ZTVALUE |
Shared (updatable) |
Stacked |
$ZTOLDVAL |
Shared |
Stacked |
$ZTDATA |
Shared |
Stacked |
$ZTSLATE |
Not Stacked |
Not Stacked |
$ZTRIGGEROP |
Shared |
Stacked |
$ZTWORMHOLE |
Not Stacked |
Not Stacked |
$ZTLEVEL |
Shared |
Stacked |
$ZTUPDATE |
depends on $ZTVALUE when trigger starts |
Stacked |
Stacked denotes an ISV whose value is restored at the completion of the trigger.
Not Stacked denotes an ISV whole value is retained after the completion of the trigger.
Shared denotes an ISV whose value is the same, possibly subject to updates, across chained updates
Note that a trigger that is both nested and chained has the characteristics from both columns - the "Chained" column is really about the relationship between triggers invoked by the same update and the "Nested" is really about the isolation of a trigger from the context that invoked it, whether or not that context is inside the context of another trigger.