Timeworked modification and sending mail

OK … I’m at wits end on this issue. We have a group that we provide change management service for that wants to also keep track of time worked on specific tickets. The first thing that I discovered was that the value of of $self->TicketObj->TimeWorked is cumulative. This was going to cause a problem because what this user wants to do is send email to the work order desk to report the time worked on a ticket as it is entered (not the total when resolved). So this meant that everytime I generated an email the work order folks were going to enter a running total each time work was performed which of course would not reflect the total time worked but far more than that.
So … since we don’t really use time worked for anything else, I decided to mess with the Ticket_Overlay.pm. I changed the pm to do the following:
sub _UpdateTimeTaken {
my $self = shift;
my $Minutes = shift;
my ($Total);
$Total = $self->SUPER::_Value(“TimeWorked”);
#$Total = ( $Total || 0 ) + ( $Minutes || 0 );

The original line is remarked out above.

The following line added.

$Total = ( 0 ) + ( $Minutes || 0 );
Field => “TimeWorked”,
Value => $Total
return ($Total);
Basically this change just keeps the last value entered and stores that as time worked. So great … now I can report the time worked to the work order desk right? Well not exactly. I wanted to do a check to see what the status of time worked was to determine if I should send email to the work order desk. If $timeworked is 0 then I don’t send to the work order desk and if it isn’t 0 then I send the email. Here is what I was trying to do:
Condition: User Defined
Action: Notify Other Recipients
Template: ukcommwo - test2 (This is a custom template I made to send to this certain group of folks.)
Stage: TransactionBatch
$RT::Logger->debug("*********** Starting time entry scrip ************\n\n");

Set Variables

Ticket Variables

my $timeworked = $self->TicketObj->TimeWorked;
if ($timeworked == 0) {
$RT::Logger->debug(“No time worked. Move on to next script.”);
return 0;
} else {
$RT::Logger->debug(“Time worked: $timeworked”);
return 1;
In my innocence I thought for sure that this would be all I needed but I ran into a ‘gotcha’. So on ticket X I want to enter a comment and some time worked. I click on comment and then I add my time and leave a comment. It works great. It detects that $timeworked isn’t 0 and generates the email. So the next time I want to comment … I click on comment and immediately an email gets generated because the value of Timeworked is not zero. Mind you this is BEFORE I even put in a comment or add time … this is just upon clicking on comment on the web interface to begin leaving a comment. So … I had an idea that I would run another scrip that would then reset the value back 0 after generating the email to the work order desk. That works but what I get is an entry on the ticket for every comment that shows the value of timeworked getting reset to 0. Cosmetically annoying and something I would like to avoid.
Does anyone have any ideas on how I can check the value of $timeworked but not generate the email when I just click on Comment to start leaving a comment? Any other tips or suggestions on how to do this would be greatly appreciated. I hoping that I’ve made this clear but since I’m typing this in a hurry and since I’m so entrenched in the problem I’m bet it is like mud to all of you. I hope not though.

  • John