Examples for MUPIP TRIGGER

This section provides step-by-step instructions for creating, modifying, and deleting triggers. Triggers affect all processes updating a database unlike, for example, environment variables such as $gtmroutines which work on a per process basis. Therefore, FIS recommends that you should always have carefully planned procedures for changing triggers in your production environment.

To create a new trigger for global node ^Acct("ID"):

  1. Using your editor, create a trigger definition file called triggers.trg with the following entry:

    +^Acct("ID") -name=ValidateAccount -commands=S -xecute="Write ""Hello Earth!"""
  2. Execute a command like the following:

    $ mupip trigger -triggerfile=triggers.trg

    This command adds a trigger for ^Acct("ID"). On successful trigger load, this command displays an output like the following:

    File triggers.trg, Line 1: ^Acct trigger added with index 1
    =========================================
    1 triggers added
    0 triggers deleted
    0 trigger file entries not changed
    0 triggers modified
    ========================================= 

    Now, every S[et] operation on the global node ^Acct("ID") executes the trigger.

  3. Execute a command like the following:

    $ mupip trigger -select="^Acct*"

    This command displays the triggers. A sample output looks like the following:

    ;trigger name: ValidateAccount#  cycle: 1
    +^Acct("ID") -name=ValidateAccount -commands=S -xecute="Write ""Hello Earth!""" 

To modify an existing trigger for global node ^Acct("ID"):

You cannot directly replace an existing trigger definition with a new one. With the exception of -NAME and -OPTIONS, to change an existing trigger, you have to delete the existing trigger definition and then add the modified trigger definition as a new trigger. Note that GT.M performs two different trigger comparisons to match trigger definitions depending on whether or not S[ET] is the trigger invocation command. If there is a S[ET], then the comparison is based on the global name and subscripts, PIECES, [Z]DELIM, and XECUTE. If there is no SET, GT.M compares only the global node with subscripts and the -XECUTE code value.

  1. Begin by executing the following command:

    $ mupip trigger -select="^Acct*"
    Output file: 
  2. Specify trigger_mod.trg as the output file. This file contains entries like the following:

    ;trigger name: ValidateAccount#  cycle: 1
    +^Acct("ID") -name=ValidateAccount -commands=S -xecute="Write ""Hello Earth!"""
  3. Using your editor, open trigger_mod.trg and change + (plus) to - (minus) for the trigger definition entry for ValidateAccount and add a new trigger definition for ^Acct("ID"). To avoid inconsistent application behavior, it is important to replace an old trigger with a new one in the same transaction (Atomic). The trigger_mod.trg file should have entries like:

    ;trigger name: ValidateAccount#  cycle: 1-^Acct("ID") -name=ValidateAccount -commands=Set -xecute="Write ""Hello Earth!"""
    ;trigger name: ValidateAccount#+^Acct("ID") -name=ValidateAccount -commands=Set -xecute="Write ""Hello Mars!""" 
  4. Execute a command like the following:

    $ mupip trigger -triggerfile=trigger_mod.trg
  5. This command displays an output like the following:

    File trigger_mod.trg, Line 1: ^Acct trigger deleted
    File trigger_mod.trg, Line 3: ^Acct trigger added with index 1
    =========================================
    1 triggers added
    1 triggers deleted
    0 trigger file entries not changed
    0 triggers modified
    =========================================

    Congratulations! You have successfully modified the xecute string of ValidateAccount with the new one.

To delete an existing trigger for global node ^Acct("ID"):

  1. Begin by executing the following command:

    $ mupip trigger -select="^Acct*"
    Output file:
  2. Specify trigger_delete.trg as the output file. This file contains entries like the following:

    ;trigger name: ValidateAccount#  cycle: 3
    +^Acct("ID") -name=ValidateAccount -commands=S -xecute="Write ""Hello Mars!"""
  3. Using your editor, change + (plus) to - (minus) for the trigger definition entry for ValidateAccount. Alternatively, you can create a file with an entry like -ValidateAccount.

  4. Now, execute a command like the following:

    $ mupip trigger -triggerfile=trigger_delete.trg

    This command displays an output like the following:

     File trigger_delete.trg, Line 2: ^Acct trigger deleted
    =========================================
    0 triggers added
    1 triggers deleted
    0 trigger file entries not changed
    0 triggers modified
    =========================================

You have successfully deleted trigger "ValidateAccount".

To change a trigger name for global node ^Acct("ID"):

  1. Using your editor, create a new file called trigger_rename.trg and add a trigger definition entry for ValidateAcct with the same trigger signature as ValidateAccount. Your trigger definition would look something like:

    +^Acct("ID") -name=ValidateAcct -commands=S -xecute="Write ""Hello Mars!"""
  2. Verify that the ValidateAccount trigger exists by executing the following command:

    $ mupip trigger -select="^Acct*"
    Output file:
  3. Respond with an empty string (Press Enter). Confirm that the trigger summary report contains an entry like the following:

    ;trigger name: ValidateAccount#  cycle: 3
    +^Acct("ID") -name=ValidateAccount -commands=S -xecute="Write ""Hello Mars!"""
  4. Now, execute a command like the following:

    $ mupip trigger -triggerfile=trigger_rename.trg

    This command displays an output like the following:

    =========================================
    0 triggers added
    0 triggers deleted
    0 trigger file entries not changed
    1 triggers modified
    =========================================

    You have successfully changed the trigger name ValidateAccount to ValidateAcct.