Scrip : reply to resolved ticket -> open a new ticket (part2)

hi,

I use RT 3.0.9 and I trying to make a scrip to automatically catch reply to
resolved ticket and create a new ticket with content from the reply catched.

In my preceding email I asked to the list the way to attach transaction
object of a current ticket to a new one. I haven’t yet managed to get it
working but I create a fake mime message (identically to the transaction),
and I create a new ticket with this mime message.

old question (answer always needed) :

I don’t know what are the revelant info that
must be copied ? Is there any method that allow to duplicate or ideally move
a correspondence from one queue to another (didn’t managed to found it in the
docs…) ?

new questions :

  • how to retrieve attached parts of the mail to attach them to the new ticket ?
    (or in which file of RT could I find a suitable example ?)

here’s follow the dirty way I have written to do it in my scrip action :

we start with a transaction and a ticket obj

my $ticket = $self->TicketObj;
my $transaction = $self->TransactionObj;

$RT::Logger->debug(“>>> Entering Custom Action <<<”);
$RT::Logger->debug(“>> Ticket : id=”. $ticket->EffectiveId );
$RT::Logger->debug(">> Transaction content : " . $transaction->Content);

compute mime message (don’t know how to import it from transaction object…)

my $message = new MIME::Entity;
$message->build(
To => $transaction->Attachments->First->GetHeader(‘To’),
From => $transaction->Attachments->First->GetHeader(‘From’),
Subject => $transaction->Subject,
Date => $transaction->Attachments->First->GetHeader(‘Date’),
Data => ‘Réponse reçue concernant le ticket résolu #’ . $ticket->Id .
“:\n\n” . $transaction->Content
);

my $child_ticket = RT::Ticket->new($RT::SystemUser);

find the email of the sender

my $user = RT::User->new($RT::SystemUser);
$user->Load($transaction->Creator);
my $mail = $user->EmailAddress;

my ($child_id, $child_TransObj, $errorMsg) =
$child_ticket->Create(Queue => $ticket->Queue,
Subject => ‘suite du ticket #’. $ticket->Id . ’ : ’ .
$ticket->Subject,
RefersTo => $ticket->Id,
MIMEObj => $message,
Requestor => $mail
);

add a comment to the resolved ticket to inform that we have open a new ticket

$ticket->Comment( Content => ‘Suite à la correspondance précédente (^^^), un
nouveau ticket à été ouvert. Voir le ticket #’ . $child_ticket->Id);

return(1);

and the condition scrip that detect correspondence or comment on resolved
ticket :

my $ticket = $self->TicketObj;
my $transaction = $self->TransactionObj;

$RT::Logger->debug(“>>> Creator: “. $transaction->Creator .
“Type:”. $transaction->Type .
“Status:”.$ticket->Status.”<<<”);
if ((($transaction->Type eq ‘Correspond’) || ($transaction->Type eq ‘Comment’))
&&
$ticket->Status eq ‘resolved’ &&
$transaction->Creator != 1){# userid 1 is RT → prevent loops

return(1);

} else {
return(undef);
}

I hope that my problem description is clear, if it is not, ask me and I will
give
you more details. Any help will be very appreciated …

Thanks for your help.

seb
rt-users mailing list
rt-users@lists.bestpractical.com
http://lists.bestpractical.com/mailman/listinfo/rt-users

Have you read the FAQ? The RT FAQ Manager lives at http://fsck.com/rtfm