[rt-users] HELP with RT API
Ken Crocker
kfcrocker at lbl.gov
Fri Aug 21 17:56:37 EDT 2009
To all,
I'm in a mess trying to figure out why RT:API will NOT put dates in the
Ticket record when I read an input file.
The dates are formatted as "yyyy-mm-dd 0:00:00". I get no errors in the log.
The Date fields "Created", "Started", "Resolved" get nada and the field
"LastUpdated" get current date, not the data I'm trying to put in it.
This is the code:
#------------------------------------------------------------------------------
# process all requests into tickets
#------------------------------------------------------------------------------
sub Read_Temp_File
{
my ( $fh ) = @_;
my
(
$in,
$objectId
);
while ( $in = <$fh> )
{
chomp $in;
$objectId = New_Ticket( $in ); #ObjectId = Ticket.id
}
}
#------------------------------------------------------------------------------
# create Ticket for one request
#------------------------------------------------------------------------------
sub New_Ticket
{
my ( $in ) = @_;
my
(
$ticket,
$mimeObj,
$ticketid,
$transaction_object,
$err,
$rc,
$NUMBER,
$DATE_OPENED,
$DATE_RESOLVED,
$REQUEST_TYPE,
$SYSTEM_AREA,
$ISSUE_DESCRIPTION,
$RESOLUTION,
# @parts,
# $new_date,
%ticket_vals
);
( $NUMBER, $DATE_OPENED, $DATE_RESOLVED, $REQUEST_TYPE,
$SYSTEM_AREA, $ISSUE_DESCRIPTION, $RESOLUTION ) = split( "\t", $in );
#your field names for your data
$ticket = RT::Ticket->new( $RT::SystemUser );
$mimeObj = MIME::Entity->build(Data => $ISSUE_DESCRIPTION, Type =>
'text/plain'); #whatever field has descr
#------------------------------------------------------------------------------
# re-format date fields in a ticket
#------------------------------------------------------------------------------
#
# if ( $DATE_OPENED )
# {
# @parts = split(/[\/-]/, $DATE_OPENED);
# my $new_date = RT::Date->new($RT::SystemUser);
# $new_date = sprintf("%d-%02d-%02d 0:00:00", $parts[2] + 2000,
$parts[0], $parts[1]);
# $DATE_OPENED = $new_date->ISO;
# $DATE_OPENED->Set(Format=>'unix', Value=>$new_date);
# $DATE_OPENED = $new_date;
# }
# print "Opened Date - ", $DATE_OPENED, ' '; #debug
#
# if ( $DATE_RESOLVED )
# {
# @parts = split(/[\/-]/, $DATE_RESOLVED);
# my $new_date = RT::Date->new($RT::SystemUser);
# $new_date = sprintf("%d-%02d-%02d 0:00:00", $parts[2] + 2000,
$parts[0], $parts[1]);
# $DATE_RESOLVED = $new_date->ISO;
# $DATE_RESOLVED->Set(Format=>'unix', Value=>$new_date);
# $DATE_RESOLVED = $new_date;
# }
#
# print "Resolved Date - ", $DATE_RESOLVED, ' '; #debug
#
#------------------------------------------------------------------------------
# build ticket values
#------------------------------------------------------------------------------
#
%ticket_vals =
(
Subject => $ISSUE_DESCRIPTION,
MIMEObj => $mimeObj,
Creator => 4233, #API bug won't look up corresponding id for name
Owner => 4233,
Requestor => 4233,
Queue => 14,
Priority => 3,
InitialPriority => 3,
FinalPriority => 3,
Created => $DATE_OPENED,
Started => $DATE_OPENED,
LateUpdated => $DATE_RESOLVED,
Resolved => $DATE_RESOLVED,
Status => ( "resolved" )
);
( $ticketid, $transaction_object, $err ) = $ticket->Create(
%ticket_vals );
print "New_Ticket request=", $NUMBER, " $err \n"; #debug
die "New_Ticket Error: $err \n" unless $ticketid;
( $rc, $err ) = $ticket->AddCustomFieldValue( Field =>
'Description', Value => $ISSUE_DESCRIPTION );
( $rc, $err ) = $ticket->AddCustomFieldValue( Field => 'Reference
Number', Value => $NUMBER );
( $rc, $err ) = $ticket->AddCustomFieldValue( Field => 'Travel-Area
of System', Value => $SYSTEM_AREA );
( $rc, $err ) = $ticket->AddCustomFieldValue( Field => 'Work-State',
Value => "Resolved" );
( $rc, $err ) = $ticket->AddCustomFieldValue( Field => 'Resolution
Type', Value => $REQUEST_TYPE );
( $rc, $err ) = $ticket->AddCustomFieldValue( Field => 'Resolution
Description', Value => $RESOLUTION );
return $ticketid; #Ticket.id
}
#
#------------------------------------------------------------------------------
# main
#------------------------------------------------------------------------------
my
(
$fh,
$fname
);
RT::LoadConfig();
RT::Init();
$fname = '/var/tmp/rt-travel-data.txt.20090817.001.12rec'; #your
input file name here
$fh = IO::File->new( "$fname" ) or die "cannot open $fname $!\n";
Read_Temp_File( $fh );
$fh->close();
I can't, for the life of me, see the problem. Of course, you can see by
the "Date Re-formatting" code that is commented out, that I just may not
know what the hell I am doing.
Can anyone PLEASE help me?
Thanks.
Kenn
LBNL
More information about the rt-users
mailing list