Extract Attachment as Mime

Hi list,

Hi try to create a scrip which will create a new ticket in an other queue,
with the last comment as body.

Description : On close Create ticket in alerts
Condition : On close
Action : Defined by user
Modèle : null
Step : TransactionCreate

Pre-action code:

return 1;

Custom action :

my $ticket = $self->TicketObj;
my $CF = $ticket->FirstCustomFieldValue(‘VALIDATION’);
my $child_ticket = RT::Ticket->new ( $RT::SystemUser );
my $queue_name = ‘Alerts’;
return 0 if ($CF ne $queue_name );

my $transactions = $ticket->Transactions;
$transactions->Limit( FIELD => ‘Type’, VALUE => ‘Comment’ );

while (my $transaction = $transactions->Next){
$RT::Logger->info("Transaction ". $transaction->id);
my $attachments = $transaction->Attachments;
while (my $attachment = $attachments->Next) {
$RT::Logger->info(“Attachment”. $attachment->id);
my $content = $attachment->ContentAsMIME;
}
}

my ($child_id, $child_transobj, $errormsg ) = $child_ticket->Create(
Queue => $queue_name ,
Subject => $ticket->Subject,
RefersTo => $ticket->id ,
Owner => $ticket->Owner ,
MIMEObj => $Content,
);

unless ( $child_id ) {
$RT::Logger->debug(">>Error : ". $errormsg);
return 0;
};
return 1;

So, without the while loop and the MIMEObj parameter, the scrip works fine,
and a new ticket is created in the other queue, but with an empty body.
When I add the loop, the scrip fail, and I don’t any error log.

Do you have any idea about this problem ?

Best regards,
Anthony

At the very least, you’ll note that these two variables aren’t the
same ($content vs $Content). However, it’s more complicated than that
since you have the declaration buried so deep in scope that the later
code can’t even see it.

At the very least, you’ll need to forward declared $Content early, set
it, and then check it before Creating.

 my $content = $attachment->ContentAsMIME;
 MIMEObj => $Content,

I’ve not ready any of the other code closely, the syntax error just
jumped out.

-kevin

Hi Kevin,

Thanks for this reply.
Effectively, with this mistake, the scrip will not be right… I did lot of
test, maybe the fatigue…
SO, I will follow your advises and get the list informed.

Regards,
Anthony2013/4/2 Kevin Falcone falcone@bestpractical.com

On Tue, Apr 02, 2013 at 03:19:36PM +0200, Anthony Brodard wrote:

At the very least, you’ll note that these two variables aren’t the
same ($content vs $Content). However, it’s more complicated than that
since you have the declaration buried so deep in scope that the later
code can’t even see it.

At the very least, you’ll need to forward declared $Content early, set
it, and then check it before Creating.

 my $content = $attachment->ContentAsMIME;
 MIMEObj => $Content,

I’ve not ready any of the other code closely, the syntax error just
jumped out.

-kevin