[rt-users] Send last message/comment from ticket to requestor on resolve

Gene LeDuc gleduc at mail.sdsu.edu
Mon May 5 14:29:01 EDT 2008


Nelson,

Here's how I include the resolver's message with our standard "resolved" 
blurb.  This is my (slightly modified) template for OnResolve.  The guts of 
what you want to do is that I grab the last correspondence, compare it to 
the last outgoing e-mail (don't include it if they're the same), then see 
if it's incoming e-mail (don't include it if so).  If it passes those 
tests, then I include it in my standard blurb to the requestor.  There are 
probably cleaner ways to do this, but I'm using this in production and it 
works.

Regards,
Gene

===== start of template contents
{ ### Tells user that ticket has been resolved
   my $MyName = "Template 28 (Resolved)";
#$RT::Logger->debug("$MyName (". $Transaction->Id . ") entered.");
   my $FromAddress = 'RT Requests <rt at myorg.org>';
   my $ContactAddress = 'real.person at myorg.org';
   my $OwnerName = $Ticket->OwnerObj->RealName;
   my $c_content;
   my $e_content;
   my $have_rmks;
   my $remarks;

   ### We won't include a comment if...
   ### - Last outgoing email content eq last correspond content (this means
   ###   that the content was already sent in an e-mail)
   ### - Last correspond attachment headers =~ /^Received/ (this means that
   ###   the correspond was an incoming e-mail)

   ### 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');
#$RT::Logger->debug("$MyName: found correspondence: '$_content'") if 
$have_rmks;
   }

   ### Get last outgoing e-mail
   $Transactions = $Ticket->Transactions;
   $Transactions->Limit( FIELD => 'Type', VALUE => 'EmailRecord' );
   $Transactions->OrderByCols (
      { FIELD => 'Created',  ORDER => 'DESC' },
      { FIELD => 'id',     ORDER => 'DESC' },
   );
   my $EmailObj = $Transactions->First;
   if ($EmailObj && $EmailObj->Id) {
     $e_content = $EmailObj->Content;
     chomp $e_content;
     if ($c_content) {
       $have_rmks = 0 if $e_content eq $c_content;
       $have_rmks = 0 if $EmailObj->Id > $CorrespondObj->Id;
     }
   }

use Mail::Address;
   my $Cc = '';
   my $Bcc = '';
   if ( $have_rmks ) {
     my $attachment = $CorrespondObj->Attachments->First;
     my @cc_addrs = Mail::Address->parse($attachment->GetHeader('RT-Send-Cc'));
     my @bcc_addrs = 
Mail::Address->parse($attachment->GetHeader('RT-Send-Bcc'));
     foreach my $addr ( @cc_addrs ) {
       $Cc .= $addr->address . ", ";
     }
     $Cc .= $Ticket->QueueObj->Cc->MemberEmailAddressesAsString;
     $Cc =~ s/, $//;

     foreach my $addr ( @bcc_addrs ) {
       $Bcc .= $addr->address . ", ";
     }
     $Bcc .= $Ticket->QueueObj->AdminCc->MemberEmailAddressesAsString;
     $Bcc =~ s/, $//;
   }

   ### Set the remarks if applicable
   if ($have_rmks) {
     $remarks = "
Comments:
====================
$c_content
====================";
#$RT::Logger->debug("$MyName: going to send comments: $remarks");
   }
   my $AddressGroup = "From: $FromAddress";
   $AddressGroup .= "\nCc: $Cc" if $Cc;
   $AddressGroup .= "\nBcc: $Bcc" if $Bcc;
   $OUT = "$AddressGroup
Subject: Action completed for your request

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

Regards,
The IT Staff";

}
===== end of template contents

At 10:42 AM 5/5/2008, Nelson Pereira wrote:
>Content-Class: urn:content-classes:message
>Content-Type: multipart/related; type="multipart/alternative";
>         boundary="----_=_NextPart_001_01C8AED7.61321FB3"
>
>Hi,
>
>Wondering how to do this:
>
>When I resolve a ticket, I want RT to send the message I put in the 
>resolve to the requestor, and not the default “as per our records
.”
>
>
>Nelson Pereira
>Senior Network Administrator


-- 
Gene LeDuc, GSEC
Security Analyst
San Diego State University 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20080505/b6177f27/attachment.htm>


More information about the rt-users mailing list