Scrip question...Getting there slowly...Time Worked

As has been mentioned I am working on trying to get a time worked scrip up
and running. So far everything is going well except for one thing, I can
retrieve dates from the ticket without problem and they come through like:

2008-02-08 21:24:49

This seems like a fine format, but once I have 2 of them, I can’t figure out
how to calculate the difference. It was suggest that I might need to convert
them to unix time and back, but I am not sure how to do that. I see that
Time::Local could possibly be used or maybe Date::Manip but my admittedly
novice Perl skills don’t particularly help me out here.

Here is the scrip as it sits, and after using RT::Logger->debug it appears
that all I need is to get the date difference calculation to work

if ($self->TicketObj->Type eq “Correspond” || $self->TicketObj->Type eq
"Comment" || $self->TicketObj->Type eq “ticket”)
{

#This is the part that is not working.
my $ticket_Worked = ($self->TicketObj->LastUpdated -
$self->TicketObj->Created);
#End part that is not working

$self->TicketObj->SetTimeWorked($ticket_Worked);
} else {
return undef;
}

The other thing that I thought was weird when I looked in my rt.log was that
when I would comment on the ticket, the returned result of the if test that
I start with was “ticket” which seems strange to me, but what do I know.
Maybe someone could explain that to me as well?

Greg Evans
Internet Support
Hood Canal Communications
(360) 898-2481 ext.212

following up on my own post to the list…The following code is mostly
working but there is a GLARING ERROR that makes it unusable

Please NOTE THE ABOVE because if you use it as is, it will require a restart
of httpd each time you try to update a ticket.

#code begin
if ($self->TicketObj->Type eq “Correspond” || $self->TicketObj->Type eq
“Comment” || $self->TicketObj->Type eq “ticket”)

Why it has to be “ticket” to work I don’t understand yet

{

Saw something similar somewhere that I was looking at RT stuff.

Looked like it may work, it does.

my $date_update=$self->TicketObj->LastUpdatedObj->Unix;
my $date_create=$self->TicketObj->CreatedObj->Unix;

my $ticket_check = $self->TicketObj->TimeWorked; #tells us the current value
of TimeWorked
my $ticket_Worked = (($date_update - $date_create)/60); #time in minutes

#this was the problem before and seems to be the problem again!!!
$self->TicketObj->SetTimeWorked($ticket_Worked);
return 1;

} else {
return undef;
}

Here is what happens when I run it as is just a quick copy/paste job of the
ticket:

Fri Feb 08 15:39:22 2008 gevans - Comments added [Reply] [Comment]
Download (untitled) [text/plain 1.2k] On Fri Feb 08 15:37:16 2008, gevans
wrote:
[snipped]

Fri Feb 08 15:39:23 2008 RT_System - TimeWorked changed from (no value)

to ‘19.1’

Fri Feb 08 15:39:23 2008 RT_System - TimeWorked changed from ‘19’ to ‘’

Fri Feb 08 15:39:23 2008 RT_System - TimeWorked changed from (no value)

to ‘21.2166666666667’

Fri Feb 08 15:39:23 2008 RT_System - TimeWorked changed from ‘21’ to ‘’

Fri Feb 08 15:39:23 2008 RT_System - TimeWorked changed from (no value)

to ‘21.2166666666667’

Fri Feb 08 15:39:23 2008 RT_System - TimeWorked changed from ‘21’ to ‘’

Fri Feb 08 15:39:23 2008 RT_System - TimeWorked changed from (no value)

to ‘21.2166666666667’

Fri Feb 08 15:39:23 2008 RT_System - TimeWorked changed from ‘21’ to ‘’


Fri Feb 08 15:42:39 2008 RT_System - TimeWorked changed from (no value)

to ‘24.4833333333333’

Fri Feb 08 15:42:39 2008 RT_System - TimeWorked changed from ‘24’ to ‘’

Fri Feb 08 15:42:39 2008 RT_System - TimeWorked changed from (no value)

to ‘24.4833333333333’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from ‘24’ to ‘’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from (no value)

to ‘24.4833333333333’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from ‘24’ to ‘’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from (no value)

to ‘24.5’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from ‘24’ to ‘’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from (no value)

to ‘24.5’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from ‘24’ to ‘’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from (no value)

to ‘24.5’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from ‘24’ to ‘’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from (no value)

to ‘24.5’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from ‘24’ to ‘’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from (no value)

to ‘24.5’

It will continue adding time until you kill httpd. This has got to be
something simple that I am missing. At least I think so… Ideas?

Thanks,

Greg Evans

[mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Greg EvansSent: Friday, February 08, 2008 2:09 PM
To: rt-users@lists.bestpractical.com
Subject: [rt-users] Scrip question…Getting there slowly…Time
Worked

As has been mentioned I am working on trying to get a time worked

scrip up and running. So far everything is going well except for one thing,
I can retrieve dates from the ticket without problem and they come through
like:

2008-02-08 21:24:49
 
This seems like a fine format, but once I have 2 of them, I can't

figure out how to calculate the difference. It was suggest that I might need
to convert them to unix time and back, but I am not sure how to do that. I
see that Time::Local could possibly be used or maybe Date::Manip but my
admittedly novice Perl skills don’t particularly help me out here.

Here is the scrip as it sits, and after using RT::Logger->debug it

appears that all I need is to get the date difference calculation to work

if ($self->TicketObj->Type eq "Correspond" || $self->TicketObj->Type

eq “Comment” || $self->TicketObj->Type eq “ticket”)
{

#This is the part that is not working.
my $ticket_Worked = ($self->TicketObj->LastUpdated -

$self->TicketObj->Created);
#End part that is not working

$self->TicketObj->SetTimeWorked($ticket_Worked);
} else {
 return undef;
}
 
 
The other thing that I thought was weird when I looked in my rt.log

was that when I would comment on the ticket, the returned result of the if
test that I start with was “ticket” which seems strange to me, but what do I
know. Maybe someone could explain that to me as well?

Greg Evans
Internet Support
Hood Canal Communications
(360) 898-2481 ext.212

following up on my own post to the list…The following code is mostly
working but there is a GLARING ERROR that makes it unusable

Please NOTE THE ABOVE because if you use it as is, it will require a restart
of httpd each time you try to update a ticket.

#code begin
if ($self->TicketObj->Type eq “Correspond” || $self->TicketObj->Type eq
“Comment” || $self->TicketObj->Type eq “ticket”)

This is wrong. you’re mixing transactions’ types and tickets’ Ticket’s
type almost always is ‘ticket’, so this if condition is true all the
time.

What condition are you using for this scrip?

Why it has to be “ticket” to work I don’t understand yet

{

Saw something similar somewhere that I was looking at RT stuff.

Looked like it may work, it does.

my $date_update=$self->TicketObj->LastUpdatedObj->Unix;
my $date_create=$self->TicketObj->CreatedObj->Unix;

my $ticket_check = $self->TicketObj->TimeWorked; #tells us the current value
of TimeWorked
my $ticket_Worked = (($date_update - $date_create)/60); #time in minutes

#this was the problem before and seems to be the problem again!!!
$self->TicketObj->SetTimeWorked($ticket_Worked);
return 1;

} else {
return undef;
}

Here is what happens when I run it as is just a quick copy/paste job of the
ticket:

Fri Feb 08 15:39:22 2008 gevans - Comments added [Reply] [Comment]
Download (untitled) [text/plain 1.2k] On Fri Feb 08 15:37:16 2008, gevans
wrote:
[snipped]

Fri Feb 08 15:39:23 2008 RT_System - TimeWorked changed from (no value)

to ‘19.1’

Fri Feb 08 15:39:23 2008 RT_System - TimeWorked changed from ‘19’ to ‘’

Fri Feb 08 15:39:23 2008 RT_System - TimeWorked changed from (no value)

to ‘21.2166666666667’

Fri Feb 08 15:39:23 2008 RT_System - TimeWorked changed from ‘21’ to ‘’

Fri Feb 08 15:39:23 2008 RT_System - TimeWorked changed from (no value)

to ‘21.2166666666667’

Fri Feb 08 15:39:23 2008 RT_System - TimeWorked changed from ‘21’ to ‘’

Fri Feb 08 15:39:23 2008 RT_System - TimeWorked changed from (no value)

to ‘21.2166666666667’

Fri Feb 08 15:39:23 2008 RT_System - TimeWorked changed from ‘21’ to ‘’


Fri Feb 08 15:42:39 2008 RT_System - TimeWorked changed from (no value)

to ‘24.4833333333333’

Fri Feb 08 15:42:39 2008 RT_System - TimeWorked changed from ‘24’ to ‘’

Fri Feb 08 15:42:39 2008 RT_System - TimeWorked changed from (no value)

to ‘24.4833333333333’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from ‘24’ to ‘’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from (no value)

to ‘24.4833333333333’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from ‘24’ to ‘’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from (no value)

to ‘24.5’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from ‘24’ to ‘’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from (no value)

to ‘24.5’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from ‘24’ to ‘’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from (no value)

to ‘24.5’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from ‘24’ to ‘’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from (no value)

to ‘24.5’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from ‘24’ to ‘’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked changed from (no value)

to ‘24.5’

It will continue adding time until you kill httpd. This has got to be
something simple that I am missing. At least I think so… Ideas?

Thanks,

Greg Evans


    From: rt-users-bounces@lists.bestpractical.com

[mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Greg Evans
Sent: Friday, February 08, 2008 2:09 PM
To: rt-users@lists.bestpractical.com
Subject: [rt-users] Scrip question…Getting there slowly…Time
Worked

    As has been mentioned I am working on trying to get a time worked

scrip up and running. So far everything is going well except for one thing,
I can retrieve dates from the ticket without problem and they come through
like:

    2008-02-08 21:24:49

    This seems like a fine format, but once I have 2 of them, I can't

figure out how to calculate the difference. It was suggest that I might need
to convert them to unix time and back, but I am not sure how to do that. I
see that Time::Local could possibly be used or maybe Date::Manip but my
admittedly novice Perl skills don’t particularly help me out here.

    Here is the scrip as it sits, and after using RT::Logger->debug it

appears that all I need is to get the date difference calculation to work

    if ($self->TicketObj->Type eq "Correspond" || $self->TicketObj->Type

eq “Comment” || $self->TicketObj->Type eq “ticket”)
{

    #This is the part that is not working.
    my $ticket_Worked = ($self->TicketObj->LastUpdated -

$self->TicketObj->Created);
#End part that is not working

    $self->TicketObj->SetTimeWorked($ticket_Worked);
    } else {
     return undef;
    }


    The other thing that I thought was weird when I looked in my rt.log

was that when I would comment on the ticket, the returned result of the if
test that I start with was “ticket” which seems strange to me, but what do I
know. Maybe someone could explain that to me as well?

    Greg Evans
    Internet Support
    Hood Canal Communications
    (360) 898-2481 ext.212

The rt-users Archives

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com

Best regards, Ruslan.

Hi Ruslan, Mike and everyone reading the list.

I have got the scrip working now, thanks for your input Mike, Ruslan,
it was a lot of help. I thought I would post it here and then ask a
follow-up question or two :slight_smile:

Here is what I have so far and it works great as long as you set the
time worked in the ticket after you first create it.

Description: Set Time Worked
Condition: On Transaction
Action: User Defined
Template: Global template: Blank
Stage: Transaction Create

Custom Condition:
Custom Action Preparation Code: 1;

Custom Action Cleanup Code:

If we reply to or comment on a ticket

$RT::Logger->debug(“Got to Stage 2”);
if ($self->TransactionObj->Type eq “Correspond” || $self-

TransactionObj->Type eq “Comment”)
{
#set our variable $ticket_Worked to the difference in time between the
Created
#datestamp and the updated datestamp

my $date_update=$self->TicketObj->LastUpdatedObj->Unix;
my $date_create=$self->TicketObj->CreatedObj->Unix;

#check current value of time worked for debug
#my $ticket_check = $self->TicketObj->TimeWorked;

#calculate the new value we will place in the TimeWorked field we are
working in unix time
#so everything is in seconds, divide by 60 to get minutes.
my $ticket_Worked = (($date_update - $date_create)/60);

#change the TimeWorked field to the value of our variable
($ticket_Worked)
$self->TicketObj->SetTimeWorked($ticket_Worked);
return 1;
} else {
return undef;
}

So, that works. now my questions.

  1. As I stated the above code works, but with one caveat. If I do not
    manually enter the time worked the first time, any updates to the
    ticket result in the time worked remaining at “0”. I can understand
    that for many organizations this would be the preferred method for
    this, because someone would create the ticket and there may be lengthy
    research involved, etc. before the ticket can be updated, however in
    the case for how we are using RT, it is for phone calls in to the
    helpdesk, and most tickets are resolved during that first call. On a
    slow day, this would not be an issue, because we could manually enter
    the time worked, though if we forget, that destroys the value of the
    time worked field. This leads to question #2

  2. When I create a new ticket, I would like to be able to do the same
    as above, but it should automatically set the time worked from when I
    clicked “New TIcket In…” to when I actually clicked the “Create”
    button. I am assuming that I should be able to do this through the
    scrip process somehow, so I decided to watch the rt.log while I
    clicked “New Ticket In…” but I saw no entries into the log file that
    would indicate that I am creating a new ticket, which I assume is
    because it will not be logging that until I actually hit the create
    button. So I am interested in knowing how would I go about
    implementing something like this, so that I can ensure hat each ticket
    gets an entry in Time Worked without any user having to manually enter
    it, or is there no way to accomplish this?

Regards,

Greg EvansOn Feb 8, 2008, at 6:37 PM, Ruslan Zakirov wrote:

On Feb 9, 2008 3:20 AM, Greg Evans gevans@hcc.net wrote:

Well, at least I know I am doing it wrong! LOL :slight_smile: Better to know
now and
learn then to regret it later.

Here is everything about how I have it set up (this is my first one
BTW, be
gentle)

Description : Set Time Worked Test
Condition : On Transaction
Action : User Defined
Template : Global template: Blank
Stage : TransactionCreate

Custom Condition: none
Custom Action preparation code: 1;
Custom Action cleanup code:
The code I sent in the previous message

I think I see what you mean regarding the object types, so I can
assume that
the beginning where I am trying to use correspond or comment should
be
‘TransactionObj->Type eq …’ instead of ‘TicketObj->Type eq …’? or
something else entirely?
TransactionObj->Type

Greg Evans
RT newbie :slight_smile:

-----Original Message-----
From: ruslan.zakirov@gmail.com
[mailto:ruslan.zakirov@gmail.com] On Behalf Of Ruslan Zakirov
Sent: Friday, February 08, 2008 4:10 PM
To: Greg Evans
Cc: rt-users@lists.bestpractical.com
Subject: Re: [rt-users] Scrip question…Getting there
slowly…Time Worked

On Feb 9, 2008 2:57 AM, Greg Evans gevans@hcc.net wrote:

following up on my own post to the list…The following
code is mostly
working but there is a GLARING ERROR that makes it unusable

Please NOTE THE ABOVE because if you use it as is, it will
require a restart
of httpd each time you try to update a ticket.

#code begin
if ($self->TicketObj->Type eq “Correspond” ||
$self->TicketObj->Type eq
“Comment” || $self->TicketObj->Type eq “ticket”)

This is wrong. you’re mixing transactions’ types and tickets’
Ticket’s
type almost always is ‘ticket’, so this if condition is true all the
time.

What condition are you using for this scrip?

Why it has to be “ticket” to work I don’t understand yet

{

Saw something similar somewhere that I was looking at RT stuff.

Looked like it may work, it does.

my $date_update=$self->TicketObj->LastUpdatedObj->Unix;
my $date_create=$self->TicketObj->CreatedObj->Unix;

my $ticket_check = $self->TicketObj->TimeWorked; #tells us
the current value
of TimeWorked
my $ticket_Worked = (($date_update - $date_create)/60);
#time in minutes

#this was the problem before and seems to be the problem again!!!
$self->TicketObj->SetTimeWorked($ticket_Worked);
return 1;

} else {
return undef;
}

Here is what happens when I run it as is just a quick
copy/paste job of the
ticket:

Fri Feb 08 15:39:22 2008 gevans - Comments added [Reply]
[Comment]
Download (untitled) [text/plain 1.2k] On Fri Feb 08
15:37:16 2008, gevans
wrote:
[snipped]

Fri Feb 08 15:39:23 2008 RT_System - TimeWorked

changed from (no value)

to ‘19.1’

Fri Feb 08 15:39:23 2008 RT_System - TimeWorked

changed from ‘19’ to ‘’

Fri Feb 08 15:39:23 2008 RT_System - TimeWorked

changed from (no value)

to ‘21.2166666666667’

Fri Feb 08 15:39:23 2008 RT_System - TimeWorked

changed from ‘21’ to ‘’

Fri Feb 08 15:39:23 2008 RT_System - TimeWorked

changed from (no value)

to ‘21.2166666666667’

Fri Feb 08 15:39:23 2008 RT_System - TimeWorked

changed from ‘21’ to ‘’

Fri Feb 08 15:39:23 2008 RT_System - TimeWorked

changed from (no value)

to ‘21.2166666666667’

Fri Feb 08 15:39:23 2008 RT_System - TimeWorked

changed from ‘21’ to ‘’


Fri Feb 08 15:42:39 2008 RT_System - TimeWorked

changed from (no value)

to ‘24.4833333333333’

Fri Feb 08 15:42:39 2008 RT_System - TimeWorked

changed from ‘24’ to ‘’

Fri Feb 08 15:42:39 2008 RT_System - TimeWorked

changed from (no value)

to ‘24.4833333333333’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked

changed from ‘24’ to ‘’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked

changed from (no value)

to ‘24.4833333333333’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked

changed from ‘24’ to ‘’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked

changed from (no value)

to ‘24.5’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked

changed from ‘24’ to ‘’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked

changed from (no value)

to ‘24.5’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked

changed from ‘24’ to ‘’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked

changed from (no value)

to ‘24.5’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked

changed from ‘24’ to ‘’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked

changed from (no value)

to ‘24.5’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked

changed from ‘24’ to ‘’

Fri Feb 08 15:42:40 2008 RT_System - TimeWorked

changed from (no value)

to ‘24.5’

It will continue adding time until you kill httpd. This
has got to be
something simple that I am missing. At least I think so… Ideas?

Thanks,

Greg Evans


   From: rt-users-bounces@lists.bestpractical.com

[mailto:rt-users-bounces@lists.bestpractical.com] On Behalf
Of Greg Evans
Sent: Friday, February 08, 2008 2:09 PM
To: rt-users@lists.bestpractical.com
Subject: [rt-users] Scrip question…Getting there
slowly…Time
Worked

   As has been mentioned I am working on trying to get

a time worked

scrip up and running. So far everything is going well
except for one thing,
I can retrieve dates from the ticket without problem and
they come through
like:

   2008-02-08 21:24:49

   This seems like a fine format, but once I have 2 of

them, I can’t

figure out how to calculate the difference. It was suggest
that I might need
to convert them to unix time and back, but I am not sure
how to do that. I
see that Time::Local could possibly be used or maybe
Date::Manip but my
admittedly novice Perl skills don’t particularly help me out here.

   Here is the scrip as it sits, and after using

RT::Logger->debug it

appears that all I need is to get the date difference
calculation to work

   if ($self->TicketObj->Type eq "Correspond" ||

$self->TicketObj->Type

eq “Comment” || $self->TicketObj->Type eq “ticket”)
{

   #This is the part that is not working.
   my $ticket_Worked = ($self->TicketObj->LastUpdated -

$self->TicketObj->Created);
#End part that is not working

   $self->TicketObj->SetTimeWorked($ticket_Worked);
   } else {
    return undef;
   }


   The other thing that I thought was weird when I

looked in my rt.log

was that when I would comment on the ticket, the returned
result of the if
test that I start with was “ticket” which seems strange to
me, but what do I
know. Maybe someone could explain that to me as well?

   Greg Evans
   Internet Support
   Hood Canal Communications
   (360) 898-2481 ext.212

The rt-users Archives

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly
Media.
Buy a copy at http://rtbook.bestpractical.com


Best regards, Ruslan.


Best regards, Ruslan.

Greg,

With apologies if this is off-base but I see process as the answer to your
problem. Whether an issue needs to be tracked for troubleshooting over the
phone, at the desk or in the server room it should be “created” from the get
go. Here’s my rationale - I look at the first comment (STATUS = New) as the
problem description. It should be short and to the point. Collect necessary
information and create the ticket. To help train your phone support to
comply with this process, make sure they provide end users with a ticket
number before they start to troubleshoot (nice customer service touch).

All comments posted after the fact (STATUS = Open OR Stalled) make up the
bulk of the ticket history and detail troubleshooting steps and
communication with the end user. When solved, the final comment (STATUS =
Resolved) is the resolution which again should be short and to the point.

This allows for reporting to include an easy to read recap of Date |
Requestor | Problem Description | Resolution | Time worked (thanks to your
scrip). If you allow front line/techs to cram all parts of an issue into one
comment that serves as problem/troubleshooting/resolution, you miss out on
important tracking steps that can help with ticket histories/trending/ and
repeatable solutions for a knowledge base. That kind of report can also be
useful in demonstrating work to end-users or management where the details of
a ticket can be confusing or perhaps even inappropriate at times.

The harder part of this process may be training everyone to separate out the
resolution as a separate event (and learning how to make it
concise/clear/valuable) but I think the end result may justify the effort.

Nat

On *Sun Feb 10 02:53:22 EST 2008 *gevans at
hcc.net<rt-users%40lists.bestpractical.com?Subject=[rt-users]%20Scrip%20question...Getting%20there%20slowly...Time%20Worked&In-Reply-To=589c94400802081837r2b17416fw111541c11c0cc85b%40mail.gmail.com>

Hi Ruslan, Mike and everyone reading the list.

I have got the scrip working now, thanks for your input Mike, Ruslan,
it was a lot of help. I thought I would post it here and then ask a
follow-up question or two :slight_smile:

Here is what I have so far and it works great as long as you set the
time worked in the ticket after you first create it.

Description: Set Time Worked
Condition: On Transaction
Action: User Defined
Template: Global template: Blank
Stage: Transaction Create

Custom Condition:
Custom Action Preparation Code: 1;

Custom Action Cleanup Code:

If we reply to or comment on a ticket

$RT::Logger->debug(“Got to Stage 2”);
if ($self->TransactionObj->Type eq “Correspond” || $self-

TransactionObj->Type eq “Comment”)
{
#set our variable $ticket_Worked to the difference in time between the
Created
#datestamp and the updated datestamp

my $date_update=$self->TicketObj->LastUpdatedObj->Unix;
my $date_create=$self->TicketObj->CreatedObj->Unix;

#check current value of time worked for debug
#my $ticket_check = $self->TicketObj->TimeWorked;

#calculate the new value we will place in the TimeWorked field we are
working in unix time
#so everything is in seconds, divide by 60 to get minutes.
my $ticket_Worked = (($date_update - $date_create)/60);

#change the TimeWorked field to the value of our variable
($ticket_Worked)
$self->TicketObj->SetTimeWorked($ticket_Worked);
return 1;
} else {
return undef;
}

So, that works. now my questions.

  1. As I stated the above code works, but with one caveat. If I do not
    manually enter the time worked the first time, any updates to the
    ticket result in the time worked remaining at “0”. I can understand
    that for many organizations this would be the preferred method for
    this, because someone would create the ticket and there may be lengthy
    research involved, etc. before the ticket can be updated, however in
    the case for how we are using RT, it is for phone calls in to the
    helpdesk, and most tickets are resolved during that first call. On a
    slow day, this would not be an issue, because we could manually enter
    the time worked, though if we forget, that destroys the value of the
    time worked field. This leads to question #2

  2. When I create a new ticket, I would like to be able to do the same
    as above, but it should automatically set the time worked from when I
    clicked “New TIcket In…” to when I actually clicked the “Create”
    button. I am assuming that I should be able to do this through the
    scrip process somehow, so I decided to watch the rt.log while I
    clicked “New Ticket In…” but I saw no entries into the log file that
    would indicate that I am creating a new ticket, which I assume is
    because it will not be logging that until I actually hit the create
    button. So I am interested in knowing how would I go about
    implementing something like this, so that I can ensure hat each ticket
    gets an entry in Time Worked without any user having to manually enter
    it, or is there no way to accomplish this?

Regards,

Greg Evans