Hi Fran,

On 10/22/2010 8:15 AM, Francis L Fabrizio wrote:
Do I have to do something specific when creating a Scrip and using Action: User 
Defined in order to get RT to process the associated template with the scrip?

I have created a custom scrip, and just for testing purposes, I made the custom 
condition, custom action prep, and custom action cleanup all set to "return 
1;", and associated my desired template with the scrip.  The scrip fires and returns 
successfully, but the template is never touched.

Are there specific steps I need to take in my custom action code in order to 
load, parse, and send notifications from a template?

Thanks,
Fran

I'm using v3.6.3, so this may not be accurate with your setup.

I know of ways to do what you want.

The way I prefer to do it is to embed the code into the template. I've found this to be fairly easy to do and it involves less code. It can also be trickier to debug because the scrip doesn't tell you what action is being taken - it's all in the template. It does make the template bigger. Almost all of my templates have embedded decision-making and data-processing routines in them. Here's a piece of one of my templates that builds a custom acknowledgment e-mail.

===== BEGIN TEMPLATE CODE
{ ### Tells user that ticket has been resolved
  my $FromAddress = 'DNS Requests <someaddr...@domain>';
  my $ContactAddress = 'm...@domain';
  my $OwnerName = $Ticket->OwnerObj->RealName;
  my $have_rmks;
  my $c_content;

  ### Get last Correspond
  my $Transactions = $Ticket->Transactions;
  $Transactions->Limit( FIELD => 'Type', VALUE => 'Correspond' );
  $Transactions->OrderByCols (
     { FIELD => 'Created',  ORDER => 'DESC' },
     { FIELD => 'id',     ORDER => 'DESC' },
  );
  my $CorrespondObj = $Transactions->First;
  if ($CorrespondObj && $CorrespondObj->Id) {
    $c_content = $CorrespondObj->Content;
    chomp $c_content;
$have_rmks = !$CorrespondObj->Attachments->First->GetHeader('Received');
  }
### Lots of other code removed
  my $AddressGroup = "From: $FromAddress";
  $AddressGroup .= "\nCc: $Cc" if $Cc;
  $AddressGroup .= "\nBcc: $Bcc" if $Bcc;
  $OUT = "$AddressGroup
Subject: Action completed

The ticket that was opened for your request for host \"$mName\" has been resolved by $OwnerName. If you have any questions about this, you can contact us at $ContactAddress.
$remarks

Regards,
Your Friendly IT Staff";
}
===== END TEMPLATE CODE

Another way to do this that actually uses a user-defined action with a template is to make the calls to the appropriate RT routines from within your scrip code. I did this with one of my scrips.

I wanted to do some non-standard things with the recipients, so I modified RT's SetRecipients() routine and stuck it into my scrip, then I call it and make calls to the Prepare() and Commit() routines to build and send an e-mail using the designated template.

===== BEGIN SCRIP CODE
### Valid e-mail for ticket, send acknowledgment
$self->SetRecipients();
$self->SUPER::Prepare();
$self->SUPER::Commit();

sub SetRecipients {
  ### custom routine to do non-standard things with the recipients
}
1;
===== END SCRIP CODE

The above code snippet is at the end of my scrip's "Custom action preparation code" block.

Regards,
Gene

Reply via email to