[rt-users] [SLA] Custom (and very imperfect) solution for parking stalled tickets

Scotto Alberto al.scotto at reply.it
Thu Jun 7 18:24:09 EDT 2012

Working with the SLA Extension, I came across the problem of stalled tickets: by default, there is no way to stop the "timer" for the due date when a ticket becomes stalled, as stated by the author in

So I've just implemented a small customization (very imperfect indeed) and I want to share it with all of you. Feel free to contribute, and please share your improvements.

First of all, a few assumptions (aka limitations):
- in $RT::ServiceBusinessHours we defined only 'Default' ServiceBusinessHours
- users will not modify the date fields we set, otherwise everything would screw up

The idea is to move the due date forward as soon as the ticket exits the stalled status. To compute the new due date we need to know when the tickets became stalled. So, we first have to save somewhere the time when it became stalled: we temporarly save it in the Resolved attribute (very dirty, I know..!), which shouldn't be used while stalled.

This solution includes two actions, two conditions, and two scrips which put everything together.

Conditions, which you can easily build thanks to sbin/rt-setup-database and the ExecModule StatusChange:
- on stalled
- on un-stall

Actions (the code is below):
- Set resolved temporarly
- Update due date on un-stall

- On stalled Set resolved temporarly
- On un-stall Update due date

I think the most important improvement would be to avoid the use of the Resolved attribute as temporary. Instead, it would be better to define a new private attribute in Ticket.pm; consequently, a new column in the DB, etc.

Of course, I will appreciate any suggestions, comments, etc.



======== Action1. Set resolved temporarly =====
my $tkt = $self->TicketObj;
my $id = $tkt->Id;
my $stalled_date = RT::Date->new( $RT::SystemUser );
my ($status, $msg) = $tkt->_Set(
       Field => 'Resolved',
       Value => $stalled_date->ISO,
       RecordTransaction => 0
unless ( $status ) {
    $RT::Logger->error("Unable to set Resolved date to ticket #$id: $msg");
    return 0;
$RT::Logger->debug("Set Resolved date of ticket #". $id . " to ". $stalled_date->ISO);
return 1;

======== Action2. Update due date on un-stall =====
my $t = $self->TicketObj;
my $id = $t->Id;
use Business::Hours;

my $now = RT::Date->new( $RT::SystemUser );
my $bhours = Business::Hours->new();
$bhours->business_hours( %{ $RT::ServiceBusinessHours{ 'Default' } } );
my $delta = $bhours->between($t->ResolvedObj->Unix, $now->Unix);
my $new_due = $bhours->add_seconds($t->DueObj->Unix, $delta);

my $due_date = RT::Date->new( $RT::SystemUser );
$due_date->Set(Format => 'unix', Value => $new_due );
# finally set new due date
my ($status, $msg) = $t->_Set(
       Field => 'Due',
       Value => $due_date->ISO,
       RecordTransaction => 0
# if the two transitions (*->stalled and stalled->*) take place out of hours,
# in the same interval, then $delta will be 0
if( !($t->DueObj->Diff($due_date)) ) {
    $RT::Logger->debug("Unable to set Due date to ticket #$id: new_due_date = old_due_date " . $due_date->ISO);
elsif ( !($status) )  {
    $RT::Logger->error("Unable to set Due date to ticket #$id: $msg");
    return 0;
# reset Resolved date
($status, $msg) = $t->_Set(
       Field => 'Resolved',
       Value => 0,
       RecordTransaction => 0
unless ( $status ) {
    $RT::Logger->error("Unable to reset Resolved date to ticket #$id: $msg");
$RT::Logger->debug("Due date updated after un-stalling ticket #". $id );
return 1;

Alberto Scotto

Via Cardinal Massaia, 83
10147 - Torino - ITALY
phone: +39 011 29100
al.scotto at reply.it


The information transmitted is intended for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20120607/65befdf5/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: blue.png
Type: image/png
Size: 2834 bytes
Desc: blue.png
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20120607/65befdf5/attachment.png>

More information about the rt-users mailing list