AddAttachmentLinksToMail: Difference between revisions

From Request Tracker Wiki
Jump to navigation Jump to search
m (2 revisions imported)
 
No edit summary
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 $res;
   my $Attachments = $Transaction-&gt;Attachments;
   my $Attachments = $Transaction-&gt;Attachments;
   $Attachments-&gt;Limit( FIELD =&gt; 'Filename', OPERATOR =&gt; '!=', VALUE =&gt; '' );
   $Attachments-&gt;Limit( FIELD =&gt; 'Filename', OPERATOR =&gt; '!=', VALUE =&gt; '' );
Line 13: Line 14:
  }
  }
   
   
  </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 $res;
   my $Attachments = $Transaction-&gt;Attachments;
   my $Attachments = $Transaction-&gt;Attachments;
   $Attachments-&gt;Limit( FIELD =&gt; 'Filename', OPERATOR =&gt; '!=', VALUE =&gt; '' );
   $Attachments-&gt;Limit( FIELD =&gt; 'Filename', OPERATOR =&gt; '!=', VALUE =&gt; '' );
Line 29: Line 31:
  }
  }
   
   
  </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 $res;
   my $Attachments = RT::Attachments-&gt;new( $Transaction-&gt;CurrentUser );
   my $Attachments = RT::Attachments-&gt;new( $Transaction-&gt;CurrentUser );
   $Attachments-&gt;Columns( qw(id TransactionId Filename ContentType Created));
   $Attachments-&gt;Columns( qw(id TransactionId Filename ContentType Created));
Line 67: Line 70:
   $res;
   $res;
  }
  }
  </nowiki>
  </pre></source>

Revision as of 06:09, 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-&gt;Attachments;
   $Attachments-&gt;Limit( FIELD =&gt; 'Filename', OPERATOR =&gt; '!=', VALUE =&gt; '' );
   while (my $a = $Attachments-&gt;Next) {
     $res .= "New attachments:\n" unless ($res);
     $res .= "  ". $RT::WebURL ."/Ticket/Attachment/". $a-&gt;TransactionId ."/". $a-&gt;id ."/". $a-&gt;Filename;
   }
   #Workaround to prevent possible commit death
   delete($Transaction-&gt;{attachments});
   $res;
 }
 
 </pre>

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

<pre>
 { my $res;
   my $Attachments = $Transaction-&gt;Attachments;
   $Attachments-&gt;Limit( FIELD =&gt; 'Filename', OPERATOR =&gt; '!=', VALUE =&gt; '' );
   while (my $a = $Attachments-&gt;Next) {
     $res .= $RT::WebURL ."/Ticket/Attachment/". $a-&gt;TransactionId ."/". $a-&gt;id ."/". $a-&gt;Filename;
     $res .= "\n              ";
   }
   #Workaround to prevent possible commit death
   delete($Transaction-&gt;{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-&gt;new( $Transaction-&gt;CurrentUser );
   $Attachments-&gt;Columns( qw(id TransactionId Filename ContentType Created));
   my $transactions = $Attachments-&gt;NewAlias('Transactions');
   $Attachments-&gt;Join(
       ALIAS1 =&gt; 'main',
       FIELD1 =&gt; 'TransactionId',
       ALIAS2 =&gt; $transactions,
       FIELD2 =&gt; 'id'
   );
   my $tickets = $Attachments-&gt;NewAlias('Tickets');
   $Attachments-&gt;Join(
       ALIAS1 =&gt; $transactions,
       FIELD1 =&gt; 'ObjectId',
       ALIAS2 =&gt; $tickets,
       FIELD2 =&gt; 'id'
   );
   $Attachments-&gt;Limit(
       ALIAS =&gt; $transactions,
       FIELD =&gt; 'ObjectType',
       VALUE =&gt; 'RT::Ticket'
   );
   $Attachments-&gt;Limit(
       ALIAS =&gt; $tickets,
       FIELD =&gt; 'EffectiveId',
       VALUE =&gt; $Ticket-&gt;id
   );
   $Attachments-&gt;Limit( FIELD =&gt; 'Filename', OPERATOR =&gt; '!=', VALUE =&gt; '' );
   while (my $a = $Attachments-&gt;Next) {
     $res .= "Ticket's attachments:\n" unless ($res);
     $res .= "  ". $RT::WebURL ."/Ticket/Attachment/". $a-&gt;TransactionId ."/". $a-&gt;id ."/". $a-&gt;Filename;
   }
   $res;
 }
 </pre>