ScripAction

From Request Tracker Wiki
Jump to navigation Jump to search

ScripAction - is Perl code formed as module or filled in CustomActionPreparationCode and CustomActionCleanupCode Scrip fields.

This code applied after Condition check when Transaction is applicable.

A ScripAction can access and change the current instance of the following objects:

Note that Per-Transaction custom fields values are not available to ScripActions, (RT sets these after the Scrip has been executed) unless you change the Global Scrip Stage from Normal to Batch in the Applies to Page for your Scrip (as described in TransactionBatchStage .)  If your Scrip is set to Batch then it will be run after all the Transactions have been created.

Some of the built-in actions are:

  • Autoreply - emails the requestor
  • Notify and NotifyAsComment - emails the correspondance to ticket recipients
  • CreateTickets - creates one or more tickets according to the specified template

Adding new actions

If you want to add additional built-in ScripActions you can do so by manually inserting rows into the ScripActions table. For example, to add a new Scrip Action for notifying Owner and AdminCCs, you can use this INSERT statement in MySQL:

   INSERT Into ScripActions(
      Name, Description, ExecModule, Argument, Creator, Created, LastUpdatedBy, LastUpdated
   ) VALUES (
     'Notify Owner and AdminCcs', 'Sends mail to the Owner and AdminCcs', 'Notify', 'Owner,AdminCc', 1, NOW(), 1, NOW()
   );

Another nice one is to avoid sending duplicate mails to Ccs who get explicitly Cced by someone who doesn't realize they'll get a copy.

   INSERT Into ScripActions(
     Name, Description, ExecModule, Argument, Creator, Created, LastUpdatedBy, LastUpdated
   ) VALUES (
     'Notify Requestors, Ccs & Other Recipients', 'Sends mail to the Ticket Requestor and Ccs, and explicitly listed Ccs and Bccs', 'Notify', 'Requestor,Cc,OtherRecipients', 1, NOW(), 1, NOW()
   );

The important columns are ExecModule and Argument. The ExecModule names the module that will perform the action. These all have the name prefix "RT::Action::". Therefore, in the above example, the module used to perform the Scrip Action is named "RT::Action::Notify". Possible actions include:

  • AutoOpen - set the ticket status to open
  • Autoreply - send an auto-reply to the requestor
  • CreateTickets - create a ticket or tickets based upon the template
  • NotifyAsComment - send a comment to the recipients in Argument
  • Notify - send a comment to the recipients in Argument
  • UserDefined - execute the custom action code

Full list of available modules for actions you can find in the lib/RT/Action/ dir. Each module has inlined documentation, you can read it with perldoc utility, for example [=perldoc lib/RT/Action/AutoOpen.pm].

Values of the Argument field are different for different modules. Many modules have no description of the format that must be used, in such a case ask on the MailingLists and then when you'll figure that out, please, send a patch to the rt developers team.

See also SendEmailAction (todo: integrate)

Managing notification actions

A common user problem is that RT sends two (or more) notifications if a user is in two recipients lists at the same time, for example in both the CCs and Requestors lists. This happens when you have two scrips one with Action 'Notify Cc' and another with 'notify requestors'. RT by default has several complex combinations, for example 'Notify Requestors, Ccs and AdminCcs'. When there is no required combination of recipients you can create your own.

The Argument for Autoreply, NotifyAsComment, and Notify should be the name of a recipient. The following recipients are possible.

  • Requestor - the person or persons making the request
  • Owner - the owner of the request
  • Cc - all the Ccs set on the ticket
  • AdminCc - all the AdminCcs set on the ticket
  • All - this is the same as "[=Requestor,Owner,Cc,AdminCc]"
  • OtherRecipients - the Ccs and Bccs set on the transaction

You can also use any combination of the above by separating multiple recipients by a comma without whitespace. For example, "Requestor,Owner" would send to requestors and owners. See the example of INSERT query above.

See also SendEmailAction (todo: integrate)

See also

Contributions, WriteCustomAction