[rt-users] Scrip help needed on date formatting

Kenneth Crocker KFCrocker at lbl.gov
Tue Mar 3 14:07:46 EST 2009


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




More information about the rt-users mailing list