Difference between revisions of "OnQueueChangeResetPriorityAndDueDate"

From Request Tracker Wiki
Jump to navigation Jump to search
(Initial version of OnQueueChangeResetPriorityAndDueDate)
(No difference)

Revision as of 01:19, 4 June 2011

On Queue Change Set Priority And DueDate

This Scrip will reset the priority and due dates to the default queue values on a ticket when the queue is change.

  • Description: On Queue Change Set Priority and DueDate
  • Condition: On Queue Change
  • Action: User Defined
  • Template: Global template: Blank
  • Stage: TransactionBatch

Custom Condition:

# blank

Custom action preparation code:

return 1;

Custom action cleanup code:

my $queue_id = $self->TransactionObj->NewValue;
my $queue = RT::Queue->new( $RT::SystemUser );
$queue->Load( $queue_id );
  1. Reset Priority
unless ( $self->TicketObj->Priority == $queue->InitialPriority ) {
  $RT::Logger->info("On Queue Change set ticket #". $self->TicketObj->id ." priority to ". $queue->InitialPriority );
  my ( $status, $msg ) = $self->TicketObj->SetPriority( $queue->InitialPriority );
  unless ( $status ) {
    $RT::Logger->error( "Unable to assign priority to ". $queue->InitialPriority );
    $RT::Logger->error( "Message: $msg" );
  }
}
# Reset Final Priority
unless ( $self->TicketObj->FinalPriority == $queue->FinalPriority ) {
  $RT::Logger->info("On Queue Change set ticket #". $self->TicketObj->id ." final priority to ". $queue->FinalPriority );
  my ( $status, $msg ) = $self->TicketObj->SetFinalPriority( $queue->FinalPriority );
  unless ( $status ) {
    $RT::Logger->error( "Unable to assign final priority to ". $queue->FinalPriority );
    $RT::Logger->error( "Message: $msg" );
  }
}
  1. Reset Due Date
my $due_date = RT::Date->new( $RT::SystemUser );
$due_date->Set( Format => 'ISO', Value => $self->TicketObj->Due );
  1. If queue doesn't specify due date, then clear this tickets due date.
# Otherwise, add that many days.
if ( $queue->DefaultDueIn == 0 ) {
  $due_date->Set( Format => 'ISO', Value => 0 );
} else {
  $due_date->SetToNow;
  $due_date->AddDays( $queue->DefaultDueIn );
}

$RT::Logger->info("On Queue Change set ticket #". $self->TicketObj->id ." due date to ". $due_date->ISO );

my ( $status, $msg ) = $self->TicketObj->SetDue( $due_date->ISO );
unless ( $status ) {
  $RT::Logger->error( "Unable to assign due date to ". $due_date->ISO );
}
return 1;