Scanning active ticket contents in perl

Howdy all…

I’d like to write a special report and in order to do so, I need to get
info from scanning replies and comments of tickets.

This shouldn’t be hard, but I just can’t figure it out. I’ve read the
RT Essentials book, the wiki, some sample code… I’m close… just
can’t seem to close the deal!

My first question is where should I be looking for this sort of info? I
couldn’t find any sample code for offline reporting. I find that
strange. I also can’t find all the methods and attributes of the RT
objects documented anywhere.

Here’s my code snippet. The Transactions->Next seems to be looping
rather than stepping through each transaction.

$tickets->LimitStatus(VALUE => ‘new’);
$tickets->LimitStatus(VALUE => ‘open’);

while (my $Ticket = $tickets->Next) {
print “Ticket “.$Ticket->id.”\n”;
while (my $txn = $Ticket->Transactions->Next) {
print “Txn “.$txn->id.”\n”;
my $attachments = RT::Attachments->new($txn->CurrentUser);
$attachments->Limit( FIELD => ‘TransactionID’, VALUE => $txn->id );
$attachments->OrderBy( FIELD => ‘Id’, ORDER => ‘ASC’ );
while ( my $a = $attachments->Next ) {
print “ContentType=”.$a->ContentType."\n";
print “ContentEncoding=”.$a->ContentEncoding."\n";
print “Content:”.substr($a->Content,0,100)."\n";
}
}
die “stop here” if $count++>5;
}

Hello Eden,

Howdy all…

I’d like to write a special report and in order to do so, I need to get
info from scanning replies and comments of tickets.

This shouldn’t be hard, but I just can’t figure it out. I’ve read the
RT Essentials book, the wiki, some sample code… I’m close… just
can’t seem to close the deal!

My first question is where should I be looking for this sort of info? I
couldn’t find any sample code for offline reporting. I find that
strange. I also can’t find all the methods and attributes of the RT
objects documented anywhere.

Here’s my code snippet. The Transactions->Next seems to be looping
rather than stepping through each transaction.

Sure, the code is looping as $ticket->Transactions each time returns
new collection, so you always start from first txn. You need somthing
like:

my $txns = $ticket->Transactions;
while ( my $txn = $txns->Next ) {

}

$tickets->LimitStatus(VALUE => ‘new’);
$tickets->LimitStatus(VALUE => ‘open’);

while (my $Ticket = $tickets->Next) {
print “Ticket “.$Ticket->id.”\n”;
while (my $txn = $Ticket->Transactions->Next) {
print “Txn “.$txn->id.”\n”;
my $attachments = RT::Attachments->new($txn->CurrentUser);
$attachments->Limit( FIELD => ‘TransactionID’, VALUE => $txn->id );
$attachments->OrderBy( FIELD => ‘Id’, ORDER => ‘ASC’ );
while ( my $a = $attachments->Next ) {
print “ContentType=”.$a->ContentType.“\n”;
print “ContentEncoding=”.$a->ContentEncoding.“\n”;
print “Content:”.substr($a->Content,0,100).“\n”;
}
}
die “stop here” if $count++>5;
}


The rt-users Archives

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com

Best regards, Ruslan.

I’d like to write a special report and in order to do so, I need to get
info from scanning replies and comments of tickets.

This shouldn’t be hard, but I just can’t figure it out. I’ve read the
RT Essentials book, the wiki, some sample code… I’m close… just
can’t seem to close the deal!

Sure, the code is looping as $ticket->Transactions each time returns
new collection, so you always start from first txn. You need somthing
like:

my $txns = $ticket->Transactions;
while ( my $txn = $txns->Next ) {

}

DOH I knew it would be simple. Thanks… it’s working now.

Robert