I have read crythias' tutorial on Ticket Events http://forums.otrs.org/viewtopic.php?f=60&t=10090 and I found it very straightforward and useful. I think it can aid me to address my new problem:
I need to dump on a text file the content of each new ticket and any of its articles upon the ticket creation and then after any update.
I'm going to use this text file to feed another application.
Looking into /opt/otrs/bin/ I found otrs.GetTicketThread.pl and I adapt the code as for crythias tutorial.
1. I defined the following /opt/otrs/Kernel/Config/Files/GSOTest.xml
Code: Select all
<?xml version="1.0" encoding="utf-8" ?>
<otrs_config version="1.0" init="Changes">
<ConfigItem Name="Ticket::EventModulePost###GSOTest" Required="0" Valid="1">
<Description Lang="en"></Description>
<Description Lang="de"></Description>
<Group>GSOTest</Group>
<SubGroup>EventModule</SubGroup>
<Setting>
<Hash>
<Item Key="Module">Kernel::System::Ticket::Event::GSOTest</Item>
<Item Key="Event">(ArticleAgentNotification|ArticleAutoResponse|ArticleBounce|ArticleCreate|ArticleCustomerNotification|ArticleFlagDelete|ArticleFlagSet|ArticleFreeTextUpdate|ArticleSend|ArticleUpdate|HistoryAdd|HistoryDelete|TicketAccountTime|TicketCreate|TicketCustomerUpdate|TicketDelete|TicketFreeTextUpdate|TicketFreeTimeUpdate|TicketLockUpdate|TicketMerge|TicketOwnerUpdate|TicketPendingTimeUpdate|TicketPriorityUpdate|TicketQueueUpdate|TicketResponsibleUpdate|TicketServiceUpdate|TicketSLAUpdate|TicketStateUpdate|TicketTitleUpdate|TicketTypeUpdate|TicketUnlockTimeoutUpdate)</Item>
</Hash>
</Setting>
</ConfigItem>
</otrs_config>
Code: Select all
# --
# Kernel/System/Ticket/Event/EventModulePostTemplate.pm - event module
# Copyright (C) 2001-2010 xxx, http://otrs.org/
# --
# $Id: EventModulePostTemplate.pm,v 1.1 2010/05/10 17:56:20 sb Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --
package Kernel::System::Ticket::Event::GSOTest;
use strict;
use warnings;
use vars qw($VERSION);
$VERSION = qw($Revision: 1.1 $) [1];
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
# get needed objects
for (
qw(
ConfigObject CustomerGroupObject CustomerUserObject DBObject EncodeObject GroupObject
HTMLUtilsObject LinkObject LockObject LogObject LoopProtectionObject MainObject
PriorityObject QueueObject SendmailObject ServiceObject SLAObject StateObject
TicketObject TimeObject TypeObject UserObject ValidObject
)
)
{
$Self->{$_} = $Param{$_} || die "Got no $_!";
}
return $Self;
}
sub Run {
my ( $Self, %Param ) = @_;
# check needed stuff
for (qw(TicketID Event Config)) {
if ( !$Param{$_} ) {
$Self->{LogObject}->Log( Priority => 'error', Message => "Need $_!" );
return;
}
}
# return 1 if $Param{Event} ne 'TicketCreate';
my %Ticket = $Self->{TicketObject}->TicketGet(
TicketID => $Param{TicketID},
UserID => 1,
);
return 1 if !%Ticket;
# return 1 if $Ticket{State} eq 'Open';
# do some stuff
# $Self->{TicketObject}->HistoryAdd(
# TicketID => $Param{TicketID},
# CreateUserID => 1,
# HistoryType => 'Misc',
# Name => 'New ticket with state other than Open!',
# );
my $OutFileName='/tmp/'.$Ticket{TicketNumber}.'_OTRS.log';
if (!open (WLOG,"> $OutFileName")) {
return 1;
}
print WLOG "=====================================================================\n";
for (qw(TicketNumber TicketID Created Queue State Priority Lock CustomerID CustomerUserID)) {
print WLOG "$_: $Ticket{$_}\n" if ( $Ticket{$_} );
}
print WLOG "---------------------------------------------------------------------\n";
my @Index = $Self->{TicketObject}->ArticleIndex( TicketID => $TicketID );
for (@Index) {
my %Article = $Self->{TicketObject}->ArticleGet( ArticleID => $_ );
for (qw(ArticleID From To Cc Subject ReplyTo InReplyTo Created SenderType)) {
print WLOG "$_: $Article{$_}\n" if ( $Article{$_} );
}
print WLOG "Body:\n";
print WLOG "$Article{Body}\n";
print WLOG "---------------------------------------------------------------------\n";
}
close(WLOG);
return 1;
}
1;

May you please help me...
Do you see something missing?
Am I completely far afield or there is some error on the code?
Thank you
Giulio
EDIT: ... found an error in my code: $TicketID must be substituted with $Param{TicketID}.
Code: Select all
...
my @Index = $Self->{TicketObject}->ArticleIndex( TicketID => $Param{TicketID} );
...