[rt-users] Scrip help needed on date formatting
Potla, Ashish Bassaliel
c_apotla at qualcomm.com
Tue Mar 3 14:40:01 EST 2009
Hey Ken,
localize the variables as follows and try it out :
my ( undef, undef, undef, $day, $mon, $year ) = localtime( time );
my $cf_value = sprintf( '%d/%02d/%02d', $year + 1900, $mon, $day );
-Ashish
________________________________________
From: rt-users-bounces at lists.bestpractical.com [rt-users-bounces at lists.bestpractical.com] On Behalf Of Kenneth Crocker [KFCrocker at lbl.gov]
Sent: Wednesday, March 04, 2009 12:37 AM
To: rt Users
Subject: [rt-users] Scrip help needed on date formatting
To all,
I'm a newbie to perl. I've written a few simple scrips and they are
working just fine. My problem lies in my lack of understanding as to why
some code will work in a perl program, but not in a scrip. We have some
good perl programmers here and they gave me some code to use to format a
date I needed.
Scenario: when a ticket has it's status changed to 'stalled', I want to
update a Custom Field with the yyyy/mm/dd format for today's date. The
code I was given for this is as follows:
Custom Action Prep Code:
# set the CF Work-Completed Date
my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;
my $cf_obj = RT::CustomField->new($RT::SystemUser);
my $cf_name = "Stalled Date";
( undef, undef, undef, $day, $mon, $year ) = localtime( time );
$cf_value = sprintf( '%d/%02d/%02d', $year + 1900, $mon, $day );
$cf_obj->LoadByName(Name=>$cf_name);
$RT::Logger->debug("Loaded\$cf_obj->Name = ". $cf_obj->Name() ."\n");
$ticket->AddCustomFieldValue(Field=>$cf_obj, Value=>$cf_value,
RecordTransaction=>0);
return 1;
I get nothing. If I change the value of $cf_value to simply
(localtime), I get the full-fledged format of "Thu Feb 26 14:54:33 2009".
So, I know the condition works and the function of update the Custom
Field works. I just cannot get the code I was given to format the date
to work as a scrip.
Anyone have some experience with this and willing to help?
Kenn
LBNL
_______________________________________________
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
Community help: http://wiki.bestpractical.com
Commercial support: sales at bestpractical.com
Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
Buy a copy at http://rtbook.bestpractical.com
More information about the rt-users
mailing list