Kevin,

I hate to bug you, but I went to your link and saw some code. I'm not a big perl guy (I can code some simple scrips, etc.) so some of it confuses me. Attached is the program I've been speaking of. I put what I thought would be the correct code in it ("set Date Fields"). It is not working. Before I added that "set Date Fields" section, the program would run, but the date fields remained empty, except the resolved date and that would have today's date.
Could you please look at it and show me what I did wrong? Thanks.

Kenn
LBNL

On 8/26/2009 6:35 AM, Kevin Falcone wrote:
On Tue, Aug 25, 2009 at 07:25:00PM -0400, Jerrad Pierce wrote:
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.
It's a known "feature" of RT e.g;
http://www.gossamer-threads.com/lists/rt/devel/82750?search_string=Backdating%20transactions;#82750

You absolutely can set dates on tickets during import, otherwise the
RT2-to-RT3 and RT1-to-RT3 importers wouldn't be able to backdate
history.  You're talking about changing an existing Transaction, which
is indeed blocked but worked around rather trivially as needed.

-kevin
_______________________________________________
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

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


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

#!/tools/bin/perl -w
#------------------------------------------------------------------------------
#   convert change request data from a Flat File from a Legacy sys to RT.
#   Turn OFF RT and then change your RT_SiteConfig.pm to turn off logging.
#   Be sure to TURN OFF all scrips either before being RT down or via DBA/SQL.
#   scrips will try to run and logging will make the program run FOREVER!!
#   flat file input can be created by via Data::Dumper;
#   Obviously, field names will be different. OUR Data Names are all CAPS_CAPS
#------------------------------------------------------------------------------
use strict;

use lib "/$RTHome/rt/perl/lib";
use lib "/$RTHome/rt/lib";

use RT;
use RT::Ticket;
use RT::Transaction;
use RT::Attachment;
use MIME::Entity;  



#------------------------------------------------------------------------------
#    process all requests into tickets
#------------------------------------------------------------------------------
sub     Read_Temp_File
{
    my ( $fh ) = @_;

    my
    (
        $in,
        $objectId
    );

    while ( $in = <$fh> )
    {
        chomp $in;
        $objectId = New_Ticket( $VAR1 );    #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,
        %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

#   set Date Fields

    If  ($DATE_OPENED)
        {
         my $opened = RT::Date->new($RT::SystemUser);
         $opened->Set(Format=>'unknown', Value=>$DATE_OPENED);
         $DATE_OPENED = $opened->ISO;
        }

    If  ($DATE_RESOLVED)
        {
         my $resolved = RT::Date->new($RT::SystemUser);
         $resolved->Set(Format=>'unknown', Value=>$DATE_RESOLVED);
         $DATE_RESOLVED = $opened->ISO;
        }

#------------------------------------------------------------------------------
#         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,
        Priority => 3,
        InitialPriority => 3,
        FinalPriority => 3,
        Started => $DATE_OPENED,
        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/unx.travel_export_data_rt.txt';     #your input file name 
here
$fh = IO::File->new( "$fname" )   or die "cannot open $fname $!\n";
Read_Temp_File( $fh );
$fh->close();
_______________________________________________
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

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


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

Reply via email to