[rt-users] Perl help in setting Due Date

Kenneth Crocker KFCrocker at lbl.gov
Fri Jun 20 13:23:23 EDT 2008


To all,


	I've been struggling for a couple days now trying to figure out what is 
wrong with my code. I have a CF defined as "Need-By Date" where my user 
puts in the date (mm/dd/yyyy) they want as a due date. I move it around 
and then try to put it into TR's Due date. The code looks like this:

# set new values for Due Date from CF Need-by-Date

my $ticket = $self->TicketObj;
my $cf_field = $ticket->FirstCustomFieldValue('Need-By Date');
my $cf_month = substr($cf_field, 0, 2);
my $cf_day = substr($cf_field, 3, 2);
my $cf_year = substr($cf_field, 6, 4);

# move data around for date format.

my $new_date = {$cf_year."-".$cf_month."-".$cf_day};

# set new value for Ticket Due Date

$ticket->SetDue($new_date);

my $cf_obj = RT::CustomField->new($RT::SystemUser);
my $cf_name = "Problem Description";
my $cf_value = $new_date;

return 1;

	I also tried using $ticket->SetDue($new_date->ISO); which didn't work. 
Then I thought that since we are on ORACLE I might need to put the data 
in the format we use as default format for dates. SO I did this:


# set new values for Due Date from CF Need-by-Date

my $ticket = $self->TicketObj;
my $cf_field = $ticket->FirstCustomFieldValue('Need-By Date');
my $cf_month = substr($cf_field, 0, 2);
my $cf_day = substr($cf_field, 3, 2);
my $cf_year = substr($cf_field, 6, 4);
my $due_month = 'Und';

# determine month for ORACLE date format.

if  ($cf_month eq '01')
     {$due_month = 'Jan';}
elsif
     ($cf_month eq '02')
     {$due_month = 'Feb';}
elsif
     ($cf_month eq '03')
     {$due_month = 'Mar';}
elsif
     ($cf_month eq '04')
     {$due_month = 'Apr';}
elsif
     ($cf_month eq '05')
     {$due_month = 'May';}
elsif
     ($cf_month eq '06')
     {$due_month = 'Jun';}
elsif
     ($cf_month eq '07')
     {$due_month = 'Jul';}
elsif
     ($cf_month eq '08')
     {$due_month = 'Aug';}
elsif
     ($cf_month eq '09')
     {$due_month = 'Sep';}
elsif
     ($cf_month eq '10')
     {$due_month = 'Oct';}
elsif
     ($cf_month eq '11')
     {$due_month = 'Nov';}
elsif
     ($cf_month eq '12')
     {$due_month = 'Dec';}

# move data around for ORACLE date format.

my $new_date = {$cf_day."-".$due_month."-".$cf_year};

# set new value for Ticket Due Date

$ticket->SetDue($new_date);

return 1;


	It seems no matter how many variations I use to set the format, it 
doesn't work. I'm no great perl guy, but I thought this wouldn't be so 
hard. I'm obviously missing something that is intrinsic to either RT or 
perl that I'm unaware of due to little experience. Can anyone help me 
here? Thanks.


Kenn
LBNL




More information about the rt-users mailing list