[rt-users] automatically set due date and priority based on customfield

Roedel, Mark MarkRoedel at letu.edu
Fri Dec 16 17:55:35 EST 2005


Here's the scrip we've got on our production server that sets both
priority and due dates on a ticket based on our 'Urgency' custom field.
It also uses the Business::Hours perl library to ensure that our
shorter-term tickets come due when we're actually here.


Custom condition:
if (($self->TransactionObj->Type eq "CustomField") and
($self->TransactionObj->Field eq "13")) {
  return(1);
} else {
  return(undef);
}



Custom action cleanup:
my $ticket = $self->TicketObj;
my $CFName = 'Urgency';
my $QueueObj = $self->TicketObj->QueueObj;
my $CFObj = RT::CustomField->new ($QueueObj->CurrentUser);
my $duedate = RT::Date->new($RT::SystemUser);
my $bus_hours_duetime = time;

use Business::Hours;
my $hours = Business::Hours->new();
my $now = time;

$CFObj->LoadByNameAndQueue(Name=>$CFName, Queue=>$QueueObj->id);
unless ($CFObj->id) {
  $RT::Logger->warning ("$CFName doesn't exist in Queue " .
$QueueObj->Name);
  return undef;
}

my $urgencyvalue = $self->TicketObj->FirstCustomFieldValue($CFObj->id);
if ($urgencyvalue eq 'Emergency') {
  $self->TicketObj->SetPriority('100');
  $self->TicketObj->SetFinalPriority('100');
  $bus_hours_duetime = $hours->add_seconds ($now, 14400);
  $duedate->Set(Format=>'unix', Value=>$bus_hours_duetime);
  $self->TicketObj->SetDue($duedate->ISO);
} elsif ($urgencyvalue eq 'Urgent') {
  $self->TicketObj->SetPriority('90');
  $self->TicketObj->SetFinalPriority('99');
  $bus_hours_duetime = $hours->add_seconds ($now, 32400);
  $duedate->Set(Format=>'unix', Value=>$bus_hours_duetime);
  $self->TicketObj->SetDue($duedate->ISO);
} elsif ($urgencyvalue eq 'Time-Sensitive') {
  $self->TicketObj->SetPriority('89');
  $self->TicketObj->SetFinalPriority('89');
  $bus_hours_duetime = $hours->add_seconds ($now, 97200);
  $duedate->Set(Format=>'unix', Value=>$bus_hours_duetime);
  $self->TicketObj->SetDue($duedate->ISO);
} elsif ($urgencyvalue eq 'High') {
  $self->TicketObj->SetPriority('75');
  $self->TicketObj->SetFinalPriority('88');
  $duedate->Set(Format=>'unknown', Value=>'15 days');
  $self->TicketObj->SetDue($duedate->ISO);
} elsif ($urgencyvalue eq 'Medium') {
  $self->TicketObj->SetPriority('50');
  $self->TicketObj->SetFinalPriority('74');
  $duedate->Set(Format=>'unknown', Value=>'3 months');
  $self->TicketObj->SetDue($duedate->ISO);
} elsif ($urgencyvalue eq 'Low') {
  $self->TicketObj->SetPriority('25');
  $self->TicketObj->SetFinalPriority('49');
  $duedate->Set(Format=>'unknown', Value=>'6 months');
  $self->TicketObj->SetDue($duedate->ISO);
} elsif ($urgencyvalue eq 'Very Low') {
  $self->TicketObj->SetPriority('1');
  $self->TicketObj->SetFinalPriority('24');
  $duedate->Set(Format=>'unknown', Value=>'1 year');
  $self->TicketObj->SetDue($duedate->ISO);
} else {
}
return(1);
 

--
Mark Roedel
Web Programmer / Analyst
LeTourneau University



-----Original Message-----
From: rt-users-bounces at lists.bestpractical.com
[mailto:rt-users-bounces at lists.bestpractical.com] On Behalf Of Matt
Nichols
Sent: Friday, December 16, 2005 1:37 PM
To: rt-users at lists.bestpractical.com
Subject: [rt-users] automatically set due date and priority based on
customfield

Hello,

I'd like to automatically set the due date and priority of new tickets 
based on a users selection of the custom field 'severity'. The creation
of 
the custom field 'severity' was the easy part. My understanding is that 
the automatic setting of due date and priority based on this custom
field 
can be accomplished with a scrip. Has anyone done anything similar to 
this?



More information about the rt-users mailing list