- 0 Talk
-
SetTimeWorkedAutomatically
Hi,
Searching on past threads, I couldn't find how to set the "TimeWorked" automatically when a ticket was resolved, taking into account the "Started" and the "Resolved" dates. This prompted me to developed the following Scrip, which uses Date::Calc to find the date difference and update the TimeWorked field. Does RT already provide such an option?
Thanks,
Miguel
- That's not what the field is meant for. It's hours spent working, not days until the ticket was closed. In general the former will be a small fraction of the latter. --Jerrad
- Condition: On Resolve
- Action: User Defined
- Template: Global template: Blank
- Stage: TransactionCreate
- Custom action preparation code: 1;
- Custom action cleanup code:
use Date::Calc qw(Delta_DHMS);
my $time_elapsed = "0";
my $not_updated = undef;
my (@diff,@date_created,@date_started,@date_resolved);
my $date_created_string = $self->TicketObj->Created;
my $date_started_string = $self->TicketObj->Started;
my $date_resolved_string = $self->TicketObj->Resolved;
if ($date_created_string =~ /(\d+)\-(\d+)\-(\d+)\s(\d+)\:(\d+)\:(\d+)/) {
@date_created = ($1, $2, $3, $4, $5, $6);
}
if ($date_started_string =~ /(\d+)\-(\d+)\-(\d+)\s(\d+)\:(\d+)\:(\d+)/) {
# if ticket is created without "new" status
if($3 == 1970){
$not_updated = "1";
}
else{
@date_started = ($1, $2, $3, $4, $5, $6);
}
}
if ($date_resolved_string =~ /(\d+)\-(\d+)\-(\d+)\s(\d+)\:(\d+)\:(\d+)/) {
@date_resolved = ($1, $2, $3, $4, $5, $6);
}
if ($not_updated){
@diff = Delta_DHMS(@date_started, @date_resolved);
}
else{
@diff = Delta_DHMS(@date_created, @date_resolved);
}
my $day_to_minutes = $diff[0] * 1440;
my $hour_to_minutes = $diff[1] * 60;
my $time_elapsed_sum = $day_to_minutes + $hour_to_minutes + $diff[2];
if($time_elapsed_sum > 0){
$time_elapsed = qq($time_elapsed_sum\.$diff[3]);
}
$RT::Logger->debug("Setting TimeWorked to: $time_elapsed");
$self->TicketObj->SetTimeWorked( $time_elapsed );