Difference between revisions of "AddAttachmentLinksToMail"

From Request Tracker Wiki
Jump to navigation Jump to search
m (2 revisions imported)
 
m
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
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]].
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]].


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


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


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


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


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

Latest revision as of 07:10, 4 March 2019

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.

<pre>
 { 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;
 }
 
 </pre>

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

<pre>
 { 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 : '';
 }
 
 </pre>

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

<pre>
 { 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;
 }
 </pre>