Wikia

Request Tracker Wiki

AddAttachmentLinksToMail

Comments0
834pages on
this wiki

This code adds list of links to files which was attached to the transaction template runs on, this mean only attachments that was attached to the current transaction, Add code into Template.

{ my $res;
   my $Attachments = $Transaction->Attachments;
   $Attachments->Limit( FIELD => 'Filename', OPERATOR => '!=', VALUE => '' );
   while (my $a = $Attachments->Next) {
     $res .= "New attachments:\n" unless ($res);
     $res .= "  ". $RT::WebURL ."/Ticket/Attachment/". $a->TransactionId ."/". $a->id ."/". $a->Filename;
   }
   #Workaround to prevent possible commit death
   delete($Transaction->{attachments});
   $res;
 }
 
 

Or for a more verbose version to match the other headers (Jerrad):

{ my $res;
   my $Attachments = $Transaction->Attachments;
   $Attachments->Limit( FIELD => 'Filename', OPERATOR => '!=', VALUE => '' );
   while (my $a = $Attachments->Next) {
     $res .= $RT::WebURL ."/Ticket/Attachment/". $a->TransactionId ."/". $a->id ."/". $a->Filename;
     $res .= "\n              ";
   }
   #Workaround to prevent possible commit death
   delete($Transaction->{attachments});
   $res = length($res) ? ' Attachments: ' . $res : '';
 }
 
 

To add links to all ticket's attachments use next Template snippet (works only with RT-3.4 and greater):

{ my $res;
   my $Attachments = RT::Attachments->new( $Transaction->CurrentUser );
   $Attachments->Columns( qw(id TransactionId Filename ContentType Created));
   my $transactions = $Attachments->NewAlias('Transactions');
   $Attachments->Join(
       ALIAS1 => 'main',
       FIELD1 => 'TransactionId',
       ALIAS2 => $transactions,
       FIELD2 => 'id'
   );
   my $tickets = $Attachments->NewAlias('Tickets');
   $Attachments->Join(
       ALIAS1 => $transactions,
       FIELD1 => 'ObjectId',
       ALIAS2 => $tickets,
       FIELD2 => 'id'
   );
   $Attachments->Limit(
       ALIAS => $transactions,
       FIELD => 'ObjectType',
       VALUE => 'RT::Ticket'
   );
   $Attachments->Limit(
       ALIAS => $tickets,
       FIELD => 'EffectiveId',
       VALUE => $Ticket->id
   );
   $Attachments->Limit( FIELD => 'Filename', OPERATOR => '!=', VALUE => '' );
   while (my $a = $Attachments->Next) {
     $res .= "Ticket's attachments:\n" unless ($res);
     $res .= "  ". $RT::WebURL ."/Ticket/Attachment/". $a->TransactionId ."/". $a->id ."/". $a->Filename;
   }
   $res;
 }
 

Photos

Add a Photo
33photos on this wiki
See all photos >

Recent Wiki Activity

See more >

Around Wikia's network

Random Wiki