Problem accessing attachments on Queue Change (in a scrip)

Hi all,

I’m running RT 3.0.10 and I am trying to setup a scrip that reads the
original e-mail on queue change, and pulls information from it (for
example to fill in some CustomFields). However I ran into some problems
accessing the original e-mail content.

I’ve tried different scrips, including some self-written ones from examples
on the rt-users list, and also the ExtractCustomFieldValues scrip (from
http://page.mi.fu-berlin.de/~pape/rt3/ExtractCustomFieldValues.tgz
http://page.mi.fu-berlin.de/~pape/rt3/ExtractCustomFieldValues.tgz ), but
I keep having the same problem: $self->TransactionObj->Attachments->First is
always empty!

The database contents is ok, and I never ran anything (like perl <5.8) that
corrupted it.

I tried this home-made scrip:

Condition: On Queue Change
Custom Condition: (empty)
Action: User Defined
Custom action preparation code:

1;

Custom action cleanup code:

require RT::Action::Generic;
use strict;
use vars qw/@ISA/ mailto:qw/@ISA/ ;
@ISA=qw(RT::Action::Generic);
my $messages = $self->TransactionObj->Attachments;

if (not $messages->First) {
$RT::Logger->debug(“Can’t find ticket’s first e-mail!”);
return 1;
} else {
$RT::Logger->debug(“OK”);
}
return 1;

Stage: TransactionCreate

With this scrip I always get “Can’t find ticket’s first e-mail!”. The
problem seems to be that the Transaction that is created on queue change
doesn’t return anything when questioned for Attachments.

However, when I replace:
my $messages = $self->TransactionObj->Attachments;
with:
my $messages = $self->TicketObj->Transactions->First->Attachments;
the scrip is referring to the original “create” Transaction, and the
Attachments will be found.

Is this wanted behaviour, and why is this the case? Why is an Attachment a
property of a Transaction, instead of a Ticket? Is there a short way to
access all Attachments of a Ticket, regardless of which Transactions they’re
in?

Thanks in advance,
Robbert

Robbert Kouprie
Technical University of Delft
The Netherlands

Kouprie, Robbert wrote:

Hi all,

I’m running RT 3.0.10 and I am trying to setup a scrip that reads the
original e-mail on queue change, and pulls information from it (for
example to fill in some CustomFields). However I ran into some problems
accessing the original e-mail content.
What does it mean? When queue changes you don’t have any current
content. Do you want first email’s content which belong to ticket? See
below you get it yourself with:
$self->TicketObj->Transactions->First->Attachments->First;

I’ve tried different scrips, including some self-written ones from
examples on the rt-users list, and also the ExtractCustomFieldValues
scrip (from
http://page.mi.fu-berlin.de/~pape/rt3/ExtractCustomFieldValues.tgz), but
I keep having the same problem:
$self->TransactionObj->Attachments->First is always empty!

The database contents is ok, and I never ran anything (like perl <5.8)
that corrupted it.

I tried this home-made scrip:

Condition: On Queue Change
Custom Condition: (empty)
Action: User Defined
Custom action preparation code:

1;

Custom action cleanup code:

You don’t need this in User Defined custom action code:
//

require RT::Action::Generic;
use strict;
//
use vars qw/@ISA/ mailto:qw/@ISA/;
@ISA=qw(RT::Action::Generic);
This too useless.

my $messages = $self->TransactionObj->Attachments;

if (not $messages->First) {
$RT::Logger->debug(“Can’t find ticket’s first e-mail!”);
return 1;
} else {
$RT::Logger->debug(“OK”);
}
return 1;

Stage: TransactionCreate

With this scrip I always get “Can’t find ticket’s first e-mail!”. The
problem seems to be that the Transaction that is created on queue
change
doesn’t return anything when questioned for Attachments.
This transaction has no attachments! What should be in attachment when
queue changes?

However, when I replace:
my $messages = $self->TransactionObj->Attachments;
with:
my $messages = $self->TicketObj->Transactions->First->Attachments;
the scrip is referring to the original “create” Transaction, and the
Attachments will be found.
sane behavior.

Is this wanted behaviour, and why is this the case? Why is an Attachment
a property of a Transaction, instead of a Ticket? Is there a short way
to access all Attachments of a Ticket, regardless of which Transactions
they’re in?
I don’t understand why you need it.
$self->TransactionObj - it’s current transaction which triggered condition.
$self->TicketObj->Transactions - it’s collection of all ticket’s
transactions.

	Ruslan.