Using SLA to Set Due Date Based on Ticket Status

Hi Craig,

I was able to get the Due date to update relative to the last update of the ticket / on status change. In local/lib/RT/Action/SLA_SetDue.pm instead of:

my $resolve_due = $self->Due(
    Ticket => $ticket,
    Level => $level,
    Type => 'Resolve',
    Time => $ticket->CreatedObj->Unix,
);

I changed Time to:

my $resolve_due = $self->Due(
    Ticket => $ticket,
    Level => $level,
    Type => 'Resolve',
    Time => $ticket->LastUpdatedObj->Unix,
);

This seems to work very well. It doesn’t seem like the most resilient solution, especially if I end up using SLA’s as intended in other queues. Perhaps I should remove the SLA scrips as global defaults, customize this script as something like local/lib/RT/Action/SLA_SetDueOnStatusChange and apply it to just the necessary queue. Better yet, I would incorporate the proper logic in with the existing SLA_SetDue.pm, but I’m not advanced enough to do that.

In the end, and for anyone else interested, this is the logic I’m using to update Due date based on Status with business hours in mind:

Config looks like this:

Set( %ServiceAgreements, (
    Levels => {
            'new' => {
                    'Resolve' => { BusinessMinutes => 8 * 60 }, # 1 day
                    BusinessHours => 'TestHours',
                    },
            'open' => {
                    'Resolve' => { BusinessMinutes => 16 * 60 }, # 2 days
                    BusinessHours => 'TestHours',
                    },
            'stalled' => {
                    'Resolve' => { BusinessMinutes => 24 * 60 }, # 3 days
                    BusinessHours => 'TestHours',
                    },
            'followup' => {
                    'Resolve' => { BusinessMinutes => 24 * 60 }, # 3 days
                    BusinessHours => 'TestHours',
                    },
            },
    QueueDefault => {
            'Test' => 'new',
    },
));

Set( %ServiceBusinessHours, (
    'TestHours' => {
            1 => { Name => 'Monday', Start => '10:00', End => '18:00' },
            2 => { Name => 'Tuesday', Start => '10:00', End => '18:00' },
            3 => { Name => 'Wednesday', Start => '10:00', End => '18:00' },
            4 => { Name => 'Thursday', Start => '10:00', End => '18:00' },
            5 => { Name => 'Friday', Start => '10:00', End => '18:00' },
            holidays => [qw(01-01 12-25])],
            },
));

As mentioned above, 'local/lib/RT/Action/SLA_SetDue.pm was modified on line 104 with:

     Time => $ticket->LastUpdatedObj->Unix,

A custom scrip was written with the following parameters:

Description: Set Due Date on Status Change
Condition: On Status Change
Action: User Defined
Template: Blank

Custom Condition: blank
Custom action preparation code:

return 1;

Custom action commit code:

my $ticket = $self->TicketObj;
my ($ret, $msg) = $ticket->SetSLA($self->TransactionObj->NewValue);
RT::Logger->error("Failed to update SLA: $msg") unless $ret;
return 1;

Thanks a bunch Craig for your assistance!

1 Like