Send mail on status change [Fixed]

Dear community,

I am trying to implement a custom scrip that send the content of a ticket on status change. So far, I implemented the following in the initialdata file :

@ScripConditions =
{ Name => ‘On Status Change to Sent’,
Description => ‘When a an outgoing report must be sent’,
ApplicableTransTypes => ‘Any’,
ExecModule => ‘StatusChange’,
Argument => ‘old: pending; new: sent’,

(at)Scrips =
{ Description => “On status change send outgoing report”,
Queue => ‘Outgoing Reports’,
ScripCondition => ‘On Status Change to Sent’,
ScripAction => ‘Notify Requestors And Ccs’,
Template => ‘CustomTemplate’

(at)Templates = (
Queue => ‘0’,
Name => ‘CustomTemplate’,
Description => ‘Template for outgoing reports’,
Content =>
'RT-Attach-Message: yes
Content-Type: text/html
{$Transaction->Content(Type => “text/html”)} ',

With this configuration, the system correctly sends an email upon status change (pending->sent) but the content of the mail being sent is always the same :
“This transaction appears to have no content”

My guess is that the “status changed” transaction doesn’t have any content like the “Correspond” or “On create” transaction since nothing has been received during this transition.

Does somebody know how I can make it work ?



Try $Transaction->Description in your template. Or $Transaction->OldValue and $Transaction->NewValue

As we could expect, the outputs respectively gave :

$Transaction->Description ==> Status changed from ‘pending’ to ‘sent’ by root
$Transaction->OldValue ==> pending
$Transaction->NewValue ==> sent

Any other ideas :slight_smile: ?

Oups, I thought wanted this part of the transaction :smiley: What do you exactly mean with “content” of a ticket?

I wanted to retrieve the content of the transaction that initially created the ticket (content of the initial mail that created the ticket) . I found a solution using a custom template and it looks like this :

@Templates = (
Queue => ‘0’,
Name => ‘CustomTemplate’,
Description => ‘Template for outgoing reports’,
Content =>
'RT-Attach-Message: yes
Content-Type: text

   my $txs = $Ticket->Transactions;
   my $output = "";
   while ( my $trans = $txs->Next ) {
      next unless $trans->HasContent && $trans->Content;
      if($trans->Description =~ m/Ticket created/){
        $output = $output . $trans->Content . "\n";
  return $output;
  }', },

Basically, the template goes through all the transactions for a given ticket. And for all transactions, it looks if the transaction has some content. If the transaction has some content and that the description of the transaction contains the string ‘Ticket created’, then it has found the content of the initial mail.

Thx for your help Vinz !

Hi Henri,

I think there’s a more elegant solution from

Puts content of the first transaction into email

{ $Ticket->Transactions->First->Content }

I think it’s safe to assume that first transaction == transaction which created the ticket